shithub: femtolisp

Download patch

ref: 6fe12400d1d8566e6e8b691676085c4b05559f7e
parent: 8dc30ea0d32f49247e0347fb4527ebc4e64eb992
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Dec 31 01:38:57 EST 2024

macro and func with the same name - prioritize macro expansion

--- a/flisp.boot
+++ b/flisp.boot
@@ -232,7 +232,7 @@
   #fn(map) list) expand-define) #fn("=000n20T20A<71051222324F1>2865215252P:" #(begin cddr #fn(nconc)
 									       #fn(map)
 									       #fn("9000n10<70A<0TF525150Fe3:" #(compile-thunk))) expand-let-syntax)
-  #fn("5000n20:" #() local-expansion-env) #fn("<000n20H3400:0<208615221A10>3873P087=B3I0A<87T0=f2F<72875115262:87;I?0486RS;I60486Z3708860:73051893>0A<890=f2162:8624C400:8625C:092<0162:8625C:092<0162:8626C:093<0162:8627C:094<0162:8860:" #(#fn(assq)
+  #fn("5000n20:" #() local-expansion-env) #fn("<000n20H3400:0<208615221A10>3873P087=B3I0A<87T0=f2F<72875115262:73051893>0A<890=f2162:87;I?0486RS;I60486Z3708860:8624C400:8625C:092<0162:8625C:092<0162:8626C:093<0162:8627C:094<0162:8860:" #(#fn(assq)
   #fn(":000n0\x8d\x8a48420AF84>3_484<^19261:" #(#fn("8000n10H3400:0<H3700<@90A<0<F5292<0=51P:" #())))
   caddr macrocall? quote λ define let-syntax) expand-in)) expand)
 	    expand-define #fn("@000n10T70051B3:070051@L085R3;07150e1@=07223740515285R3@025268586<e3e2:252685<2728e185=e129865185<54e3e2:" #(cddr
binary files a/flisp.boot.builtin b/flisp.boot.builtin differ
--- a/system.lsp
+++ b/system.lsp
@@ -904,12 +904,12 @@
           (cond ((and bnd (cons? (cdr bnd)))  ; local macro
                  (expand-in (apply (cadr bnd) (cdr e))
                             (local-expansion-env (caddr bnd) env)))
+                ((macrocall? e) => (λ (f)
+                                     (expand-in (apply f (cdr e)) env)))
                 ((or bnd                      ; bound lexical or toplevel var
                      (not (symbol? head))
                      (bound? head))
                  (default))
-                ((macrocall? e) =>      (λ (f)
-                                          (expand-in (apply f (cdr e)) env)))
                 ((eq? head 'quote)      e)
                 ((eq? head 'λ)          (expand-lambda e env))
                 ((eq? head 'lambda)     (expand-lambda e env))
--- a/test/unittest.lsp
+++ b/test/unittest.lsp
@@ -466,5 +466,11 @@
   (princ "lz packing at level " level ": " (sizeof in) " → " (sizeof packed))
   (newline))
 
+;; macro vs function priority
+(define (!! x y) (- x y))
+(assert (eq? 3 (!! 5 2)))
+(define-macro (!! x y z) (+ z (apply !! (list x y))))
+(assert (eq? 4 (!! 5 2 1)))
+
 (princ "all tests pass")
 (newline)