git.fiddlerwoaroof.com
Browse code

feat(curly-reader): add function macro

Edward authored on 23/12/2020 20:06:46
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 (defpackage :curly-bracens
2
-  (:use :cl :named-readtables))
2
+  (:use :cl :named-readtables)
3
+  (:shadow :if :function :return))
3 4
 (in-package :curly-bracens)
4
-(shadow 'if)
5 5
 
6 6
 (defmacro if (condition then &optional (else-sym nil e-s-p) (else nil e-p))
7 7
   (assert (and e-s-p e-p (eq else-sym 'else)))
... ...
@@ -9,6 +9,15 @@
9 9
           ,then
10 10
           ,else))
11 11
 
12
+(defmacro function (&body info)
13
+  (cl:if (symbolp (car info))
14
+      (destructuring-bind (name args &rest body) info
15
+         `(defun ,name ,args
16
+            ,@body))
17
+      (destructuring-bind (args &rest body) info
18
+        `(lambda ,args
19
+           ,@body))))
20
+
12 21
 (defun read-progn (stream char)
13 22
   (declare (ignore char))
14 23
   (cons 'progn
... ...
@@ -19,6 +28,26 @@
19 28
   (:macro-char #\} (lambda (&rest r) (declare (ignore r))) nil)
20 29
   (:macro-char #\{ 'read-progn nil))
21 30
 
31
+(defvar return 'return)
32
+
33
+
34
+
35
+
36
+
37
+
38
+(function do_thing () {
39
+  return 1;
40
+})
41
+
42
+(function () {
43
+  return 1;
44
+})
45
+
46
+
47
+
48
+
49
+
50
+
22 51
 (if (> 3 1) {
23 52
   (princ :hi)
24 53
   (terpri)