[honu] use a function keyword to define procedures and make lambdas
This commit is contained in:
parent
1b6cf730c3
commit
54449d824c
|
@ -46,7 +46,13 @@
|
||||||
(define-honu-syntax honu-function
|
(define-honu-syntax honu-function
|
||||||
(lambda (code context)
|
(lambda (code context)
|
||||||
(syntax-parse code #:literal-sets (cruft)
|
(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 ...)
|
(#%braces code ...)
|
||||||
. rest)
|
. rest)
|
||||||
(values
|
(values
|
||||||
|
|
|
@ -371,6 +371,7 @@
|
||||||
(when (not (stx-null? unparsed))
|
(when (not (stx-null? unparsed))
|
||||||
(raise-syntax-error 'parse "found unparsed input" unparsed))
|
(raise-syntax-error 'parse "found unparsed input" unparsed))
|
||||||
(values (parse-all #'(more ...)) #'rest)]
|
(values (parse-all #'(more ...)) #'rest)]
|
||||||
|
#;
|
||||||
[(left:no-left function:honu-function . rest)
|
[(left:no-left function:honu-function . rest)
|
||||||
(values #'function.result #'rest)]
|
(values #'function.result #'rest)]
|
||||||
[else (syntax-parse #'head
|
[else (syntax-parse #'head
|
||||||
|
|
|
@ -80,10 +80,10 @@
|
||||||
(test
|
(test
|
||||||
"function call"
|
"function call"
|
||||||
@input{
|
@input{
|
||||||
foo(x){
|
function foo(x){
|
||||||
x * 2
|
x * 2
|
||||||
}
|
}
|
||||||
foo(5);
|
foo(5)
|
||||||
}
|
}
|
||||||
|
|
||||||
@output{10
|
@output{10
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#lang honu
|
#lang honu
|
||||||
|
|
||||||
|
function foo(x){
|
||||||
foo(){
|
1 + x * 2
|
||||||
1 + 2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foo(5)
|
||||||
|
|
|
@ -19,18 +19,18 @@ class Xml(data){
|
||||||
getData(){ data }
|
getData(){ data }
|
||||||
}
|
}
|
||||||
|
|
||||||
read_xml(){
|
function read_xml(){
|
||||||
xml_permissive_xexprs(true)
|
xml_permissive_xexprs(true)
|
||||||
xml_xml_to_xexpr(xml_document_element(xml_read_xml()))
|
xml_xml_to_xexpr(xml_document_element(xml_read_xml()))
|
||||||
}
|
}
|
||||||
|
|
||||||
loadXml(file){
|
function loadXml(file){
|
||||||
withInputFromFile(file){
|
withInputFromFile(file){
|
||||||
new Xml(read_xml())
|
new Xml(read_xml())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
starts_with(start, what){
|
function starts_with(start, what){
|
||||||
substring(what, 0, string_length(start)) string_equal start
|
substring(what, 0, string_length(start)) string_equal start
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user