/g/ - Technology

[X]

(for post deletion)
(12.00 MiB max)
Mark sensitive


File: Screenshot_at_2023-06-21_0(...).png (10.15 KiB) [Draw]
Scheme syntax rule question. Anonymous 06/21/23(Wed)09:57:35 No. 6XYD26EZ
I created a hygienic macro called `fork` that creates a lambda function which chains comparison functions together like this. (fork number? and integer?) -> (lambda (x) (and (number? x) (integer? x))) Or more generally, (fork check1 connector check2) -> (lambda (x) (connector (check1 x) (check2 x))) It can take variable terms and it has the same behavior so that you can write more complicated definitions. The macro I wrote has the same behavior as (fork check1 connector1 check2 connector2 check3) -> (lambda (x) (connector2 (connector1 (check1 x) (check2 x)) (check3 x))) But it defines more lambda functions than that. Pic related is the actual definition. I am wondering whether or not it's possible to write a hygienic definition of the fork macro that takes any number of arguments, but only defines one lambda function. I want to use syntax-case or define-syntax, No defmacro macros. Also the reason I defined it as a macro instead of a function was because `and` and `or` are macros in scheme so you can't pass them to functions as parameters (at least to my knowledge).
>>
Anonymous 08/06/23(Sun)03:05:57 No. LLRVP5JN
I think I found out a way to do it that only defines the functions once. (define-syntax fork (syntax-rules () ((_ proc1 connector proc2 ) (lambda (x) (connector (proc1 x) (proc2 x)))) ((_ other other* ... proc1 connector proc2 ) (let ((foo (fork proc1 connector proc2))) (fork other other* ... foo )))))
>>
Anonymous 08/17/23(Thu)00:43:09 No. 0JHUKZ9K
I just realized I can define syntax rules with accumulators after I accidentally made one. Pretty cool. (define-syntax easy-define-symbols (syntax-rules () ((_ () code ...) (begin code ...)) ((_ ( sym syms ...) code ...) (define-multi (syms ...) code ... (define sym (quote sym) )))))
>>
Anonymous 08/17/23(Thu)00:46:40 No. R6HZATRN
>>0JHUKZ9K Now I want to try making a macro with two recursive calls.

[Post a Reply] 3 / 0

Delete Post: [File Only]
[Home] [Rules] [FAQ]

All trademarks and copyrights on this page are owned by their respective parties.

v0.1.1

Theme: