[honu] add flow operator which composes functions from right to left
This commit is contained in:
parent
d4763da563
commit
0bac61f538
|
@ -17,10 +17,11 @@
|
|||
[honu-+ +] [honu-- -]
|
||||
[honu-* *] [honu-/ /]
|
||||
[honu-^ ^]
|
||||
[honu-flow \|]
|
||||
[honu-dot |.|]
|
||||
[honu-cons ::]
|
||||
[honu-and and]
|
||||
[honu-or or]
|
||||
[honu-and and] [honu-and &&]
|
||||
[honu-or or] [honu-or \|\|]
|
||||
[honu-structure structure]
|
||||
[literal:honu-= =]
|
||||
[literal:semicolon |;|]
|
||||
|
|
|
@ -97,13 +97,15 @@
|
|||
(cond
|
||||
[(honu-struct? left*) (let ([use (honu-struct-get left*)])
|
||||
(use left* 'right))]
|
||||
[else (error 'dot "don't know how to deal with ~a" 'left)]))
|
||||
#;
|
||||
#'(let ([left* left])
|
||||
(cond
|
||||
[(list? left*)
|
||||
(list-ref left* right)]
|
||||
[else (error 'dot "don't know how to deal with ~a and ~a" 'left 'right)])))))
|
||||
;; possibly handle other types of data
|
||||
[else (error 'dot "don't know how to deal with ~a" 'left)])))))
|
||||
|
||||
(provide honu-flow)
|
||||
(define-honu-operator/syntax honu-flow 0.001 'left
|
||||
(lambda (left right)
|
||||
(with-syntax ([left left]
|
||||
[right right])
|
||||
#'(right left))))
|
||||
|
||||
(define-binary-operator honu-+ 1 'left +)
|
||||
(define-binary-operator honu-- 1 'left -)
|
||||
|
|
|
@ -250,11 +250,11 @@
|
|||
(if current
|
||||
(let ()
|
||||
(debug "function call ~a\n" left)
|
||||
(values (left (with-syntax ([current current]
|
||||
(define call (left (with-syntax ([current current]
|
||||
[(parsed-args ...)
|
||||
(parse-comma-expression #'(args ...)) ])
|
||||
#'(current parsed-args ...)))
|
||||
#'(rest ...)))
|
||||
#'(current parsed-args ...))))
|
||||
(do-parse #'(rest ...) precedence left call))
|
||||
(let ()
|
||||
(debug "inner expression ~a\n" #'(args ...))
|
||||
(define-values (inner-expression unparsed) (parse #'(args ...)))
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
(define-lex-abbrev string-character (:or (:: #\\ any-char)
|
||||
(:~ #\")))
|
||||
(define-lex-abbrev string (:: #\" (:* string-character) #\"))
|
||||
(define-lex-abbrev operator (:or "+" "=" "*" "/" "-" "^"))
|
||||
(define-lex-abbrev operator (:or "+" "=" "*" "/" "-" "^" "||" "|" "&&"))
|
||||
(define-lex-abbrev block-comment (:: "/*"
|
||||
(complement (:: any-string "*/" any-string))
|
||||
"*/"))
|
||||
|
|
Loading…
Reference in New Issue
Block a user