Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e008d80
Showing
3 changed files
with
74 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Some syntax transformation excercises in scheme. Just seeing what's possible with macros, etc. |
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,53 @@ | ||
#lang scheme/base | ||
|
||
(define list-contains-char? | ||
(lambda (lst search) | ||
(cond | ||
((null? lst) #f) | ||
((equal? (car lst) search) #t) | ||
(else | ||
(list-contains-char? (cdr lst) | ||
search))))) | ||
|
||
(define string->split | ||
(lambda (str token) | ||
(let ((chars (string->list str))) | ||
(letrec | ||
((f (lambda (before after) | ||
(cond | ||
((null? after) | ||
(list before after)) | ||
((equal? (car after) token) | ||
(list before | ||
(cdr after))) | ||
(else | ||
(f (cons (car after) | ||
before) | ||
(cdr after))))))) | ||
(let ((x (f '() chars))) | ||
(list | ||
(list->string (reverse (car x))) | ||
(cdr x))))))) | ||
|
||
(define split_obj_and_args | ||
(lambda (obj_and_args) | ||
(string->split obj_and_args #\.))) | ||
|
||
(define transform-syntax | ||
(lambda (syntax) | ||
(cond | ||
((list-contains-char? (string->list (symbol->string (car syntax))) | ||
#\.) | ||
(let ((sym_and_args (split_obj_and_args (symbol->string (car syntax))))) | ||
|
||
(cons | ||
(quote __message_send__) | ||
(cons | ||
(string->symbol (car sym_and_args)) | ||
(cons | ||
(cdr sym_and_args) | ||
'()))))) | ||
(else | ||
syntax)))) | ||
|
||
(provide transform-syntax) |
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,20 @@ | ||
#!/usr/bin/env mzscheme | ||
#lang scheme/base | ||
|
||
(require (planet schematics/schemeunit:3) | ||
"syntax_transformer.ss") | ||
|
||
; test the framework | ||
(check-equal? #t #t "true is true") | ||
|
||
(check-equal? | ||
(transform-syntax (quote (foo bar baz))) | ||
(quote (foo bar baz))) | ||
|
||
(check-equal? | ||
(transform-syntax (quote (foo.bar))) | ||
(quote (__message_send__ foo (quote bar)))) | ||
|
||
(check-equal? | ||
(transform-syntax (quote (bar.baz))) | ||
(quote (__message_send__ bar (quote baz)))) |