forked from zack-bitcoin/chalang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wrote some libraries for the new powerful macro system
- Loading branch information
1 parent
4b1b574
commit 3fcaec4
Showing
7 changed files
with
468 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
(macro = (A B) | ||
'(nop A B === swap drop swap drop)) | ||
(macro cond (X)%this cond is a macro. it generates byte code. | ||
(cond (((= X ()) '(nop))%this cond is part of the pre-processor. It cannot generate byte code. | ||
(true '(nop | ||
`(car (car X)) | ||
if | ||
`(car (cdr (car X))) | ||
else | ||
(cond `(cdr X)) | ||
then))))) | ||
(cond (((= 4 5) 3) | ||
(false 2) | ||
(true 1))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(macro = (A B) | ||
(quote nop A B === swap drop swap drop)) | ||
(macro twos (X) | ||
(cond (((= X 0) '(nil)) | ||
(true '(cons 2 (twos (- X 1))))))) | ||
(macro things (X Y) | ||
(cond (((= X 0) '(nil)) | ||
(true '(cons Y (things (- X 1) Y)))))) | ||
|
||
|
||
(= (things 3 5) (cons 5 (cons 5 (cons 5 nil)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
(macro square (X) (* X X)) | ||
(macro = (A B) | ||
'(nop A B === swap drop swap drop)) | ||
|
||
|
||
(macro sqr (X) | ||
(cond (((= X ()) '(nil)) | ||
((is_list X) '(cons (square `(car X)) | ||
(sqr `(cdr X)))) | ||
(true X)))) | ||
(macro tree (X) | ||
(cond (((= X ()) '(nil)) | ||
((not (is_list X)) X) | ||
((is_list (car X)) '(cons `(tree (car X)) | ||
`(tree (cdr X)))) | ||
(true '(cons `(car X) | ||
`(tree (cdr X))))))) | ||
|
||
(and | ||
(= (sqr (2 3)) | ||
(cons 4 (cons 9 nil))) | ||
(= (tree (4 9)) | ||
(cons 4 (cons 9 nil)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.