Re: Read characters from without newline
Thank you all for your pointers, hints and solutions! I shall try them out : ) Best regards, Zelphir On 8/29/21 1:47 AM, Tim Meehan wrote: > Second for guile-termios, I use it and like it very much (saved my bacon > with a program I was writing). > > On Sat, Aug 28, 2021 at 3:56 PM Frank Terbeck > wrote: > >> Mike Gran wrote: >> […] >>> There is a binding of tcsetattr in the (ncurses extra) library >>> in guile-ncurses, but since you just need a couple of functions, you >>> could wrap them in FFI, I suppose. >> Shameless plug: https://gitlab.com/ft/guile-termios >> >> I sort of have this ready for guix, too. But I never got around to actu- >> ally submitting it. >> >> >> Regards, Frank >> -- >> In protocol design, perfection has been reached not when there is >> nothing left to add, but when there is nothing left to take away. >> -- RFC 1925 >> >>
syntax-case equivalent to syntax-rules
hello, i write a macro that needs both the features of syntax-rules and syntax-case based on documentation: https://www.gnu.org/software/guile/manual/html_node/Syntax-Case.html i have : ;; scheme@(guile-user)> (def (foo) (when #t (return "hello") "bye")) ;; scheme@(guile-user)> (foo) ;; "hello" ;; (def x) ;; TODO: study def of a recursive function (define-syntax def (lambda (stx) (syntax-case stx (declare) ;; definition without a value assigned ;; (def x) ((_ var) #`(define var '())) ;; (def x 7) ((_ var expr) #`(define var expr)) ;; added body body* ;;((_ (declare var1) * ...) #`(letrec ((var1 '())) * ...)) ;; 'compiles' but do not have the expected behavior: ((_ (declare var1 ...) ...) #`(letrec ((var1 '()) ...) ...)) ;; (def (foo) (when #t (return "hello") "bye")) ((_ ( ...) * ...) (let ((ret-id (datum->syntax stx 'return))) #`(define ( ...) (call/cc (lambda (#,ret-id) * ... and def2 that have the good behavior: scheme@(guile-user)> (def2 (declare x y z) (list x y z)) $1 = (() () ()) (define-syntax def2 (syntax-rules (declare) ((_ (declare var1 ...) ...) (letrec ((var1 '()) ...) ... i want to merge def and def2 in a single macro any solution? Damien
Re: syntax-case equivalent to syntax-rules
i find myself that the order of cases in syntax-case and macros is important, complex case must be put before simplest ones in order to avoid them to be parsed before, unless that they are shadowed by simplest ones... the solution was just to reorder them from complex -> simple ones: (define-syntax def (lambda (stx) (syntax-case stx (declare) ;; (def (declare x y z) 1 2 (list x y z)) ;; (() () ()) ((_ (declare var1 ...) ...) #`(letrec ((var1 '()) ...) ...)) ;; (def (foo) (when #t (return "hello") "bye")) ((_ ( ...) ...) (let ((ret-id (datum->syntax stx 'return))) #`(define ( ...) (call/cc (lambda (#,ret-id) ...) ;; definition without a value assigned ;; (def x) ((_ var) #`(define var '())) ;; (def x 7) ((_ var expr) #`(define var expr)) ))) On Sun, Aug 29, 2021 at 1:29 PM Damien Mattei wrote: > hello, > > i write a macro that needs both the features of syntax-rules and > syntax-case based on documentation: > https://www.gnu.org/software/guile/manual/html_node/Syntax-Case.html > > i have : > > ;; scheme@(guile-user)> (def (foo) (when #t (return "hello") "bye")) > ;; scheme@(guile-user)> (foo) > ;; "hello" > > ;; (def x) > > ;; TODO: study def of a recursive function > (define-syntax def > > (lambda (stx) > (syntax-case stx (declare) > > ;; definition without a value assigned > ;; (def x) > ((_ var) #`(define var '())) > > ;; (def x 7) > ((_ var expr) #`(define var expr)) > > ;; added body body* > ;;((_ (declare var1) * ...) #`(letrec ((var1 '())) > * ...)) > > ;; 'compiles' but do not have the expected behavior: > ((_ (declare var1 ...) ...) #`(letrec ((var1 '()) ...) >...)) > > ;; (def (foo) (when #t (return "hello") "bye")) > ((_ ( ...) * ...) > (let ((ret-id (datum->syntax stx 'return))) >#`(define ( ...) >(call/cc (lambda (#,ret-id) * ... > > and def2 that have the good behavior: > > scheme@(guile-user)> (def2 (declare x y z) (list x y z)) > $1 = (() () ()) > > (define-syntax def2 > > (syntax-rules (declare) > > ((_ (declare var1 ...) ...) (letrec ((var1 '()) ...) > ... > > i want to merge def and def2 in a single macro > > any solution? > > Damien >