[honu] use a function keyword to define procedures and make lambdas

This commit is contained in:
Jon Rafkind 2012-01-30 11:45:41 -07:00
parent 1b6cf730c3
commit 54449d824c
5 changed files with 17 additions and 9 deletions

View File

@ -46,7 +46,13 @@
(define-honu-syntax honu-function
(lambda (code context)
(syntax-parse code #:literal-sets (cruft)
[(_ (#%parens arg:identifier ...)
[(_ name:identifier (#%parens (~seq arg:identifier (~optional honu-comma)) ...)
(#%braces code ...) . rest)
(values
#'(%racket (define (name arg ...) (parse-body code ...)))
#'rest
#f)]
[(_ (#%parens (~seq arg:identifier (~optional honu-comma)) ...)
(#%braces code ...)
. rest)
(values

View File

@ -371,6 +371,7 @@
(when (not (stx-null? unparsed))
(raise-syntax-error 'parse "found unparsed input" unparsed))
(values (parse-all #'(more ...)) #'rest)]
#;
[(left:no-left function:honu-function . rest)
(values #'function.result #'rest)]
[else (syntax-parse #'head

View File

@ -80,10 +80,10 @@
(test
"function call"
@input{
foo(x){
function foo(x){
x * 2
}
foo(5);
foo(5)
}
@output{10

View File

@ -1,6 +1,7 @@
#lang honu
foo(){
1 + 2
function foo(x){
1 + x * 2
}
foo(5)

View File

@ -19,18 +19,18 @@ class Xml(data){
getData(){ data }
}
read_xml(){
function read_xml(){
xml_permissive_xexprs(true)
xml_xml_to_xexpr(xml_document_element(xml_read_xml()))
}
loadXml(file){
function loadXml(file){
withInputFromFile(file){
new Xml(read_xml())
}
}
starts_with(start, what){
function starts_with(start, what){
substring(what, 0, string_length(start)) string_equal start
}