Skip to content

Commit

Permalink
warn when assigning to a function variable
Browse files Browse the repository at this point in the history
http://arclanguage.org/item?id=19687

Just an initial experiment. Let's see what it breaks.
  • Loading branch information
akkartik committed Apr 27, 2016
1 parent 4e3b077 commit b7d17d8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions arc.arc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ If you find others, please report them at http://arclanguage.org/forum.
(disp ',var (stderr)) (disp ',var (stderr))
(disp #\newline (stderr)))))) (disp #\newline (stderr))))))


(remac assign-and-warn (var val)
"Like assign for just a single variable, but warn if any of the variables
being assigned to already contains a function."
`((fn () (if (bound ',var)
(if (is (type ,var) 'fn)
((fn () (disp "*** redefining " (stderr))
(disp ',var (stderr))
(disp #\newline (stderr))))))
(assign ,var ,val))))

(remac mac (name parms . body) (remac mac (name parms . body)
"Defines a new *macro*, or abbreviation for some more complex code. "Defines a new *macro*, or abbreviation for some more complex code.
Macros are the hallmark of lisp, the ability to program on programs. Macros are the hallmark of lisp, the ability to program on programs.
Expand All @@ -91,7 +101,7 @@ Or come ask questions at http://arclanguage.org/forum"
(cons nil body))) (cons nil body)))
(remac ,name ,parms ,@body)))) (remac ,name ,parms ,@body))))


(assign examples* (table)) (assign-and-warn examples* (table))


(mac examples (name . tests-and-expected-results) (mac examples (name . tests-and-expected-results)
"Shows some example calls of a function as an enhancement of its docstring. "Shows some example calls of a function as an enhancement of its docstring.
Expand Down Expand Up @@ -870,7 +880,7 @@ table, or other user-defined type) to 'value'.")
(w/uniq (g h) (w/uniq (g h)
(list (list g expr) (list (list g expr)
g g
`(fn (,h) (assign ,expr ,h))))) `(fn (,h) (assign-and-warn ,expr ,h)))))
; make it also work for uncompressed calls to compose ; make it also work for uncompressed calls to compose
(and (acons expr) (metafn (car expr))) (and (acons expr) (metafn (car expr)))
(setforms (expand-metafn-call (ssexpand (car expr)) (cdr expr))) (setforms (expand-metafn-call (ssexpand (car expr)) (cdr expr)))
Expand Down Expand Up @@ -910,7 +920,7 @@ table, or other user-defined type) to 'value'.")


(def expand= (place val) (def expand= (place val)
(if (and (isa place 'sym) (~ssyntax place)) (if (and (isa place 'sym) (~ssyntax place))
`(assign ,place ,val) `(assign-and-warn ,place ,val)
(let (vars prev setter) (setforms place) (let (vars prev setter) (setforms place)
(w/uniq g (w/uniq g
`(atwith ,(+ vars (list g val)) `(atwith ,(+ vars (list g val))
Expand Down

0 comments on commit b7d17d8

Please sign in to comment.