4 ms·
Really, an ERROR? Could you show the actual message that was printed? You can't, because you did not even bother to try. Here is an actual test: (defun squ
by junke 10y ago
Really, an ERROR? Could you show the actual message that was printed? You can't, because you did not even bother to try.
Here is an actual test:
(defun square (x)
(* x x))
(defmacro hypotenuse (x y)
`(sqrt (+ (square ,x) (square ,y))))
;; whatever
(defun make-square (s) (list :square s))
(defun foo (s)
(let* ((square (make-square s))
(diagonal (hypotenuse s s)))
diagonal))
Now, let's compile (SBCL):
; caught STYLE-WARNING:
; The variable SQUARE is defined but never used.
Not really what you expected, right?
(foo 10)
=> 14.142136
It looks like it works.
You are trying to apply Scheme's semantics to CL. You forgot to take into account CL namespaces, which consist of (1) function/classes/type/variable namespaces and (2) namespaces defined by packages (or custom mappings).
> namespace n. 1. bindings whose denotations are restricted to a particular kind. ``The bindings of names to tags is the tag namespace.'' 2. any mapping whose domain is a set of names. ``A package defines a namespace.''
(http://clhs.lisp.se/Body/26_glo_n.htm http://clhs.lisp.se/Body/26_glo_n.htm)
If you defined a local function named square, that could have been the beginning of a point. However, I don't buy the idea that inside a single package, someone is going to shadow a function that belongs to the same package, in a macro (if this happens, it is more likely to be done on purpose).
As for shadowing function bindings from other packages, this is even more improbable.
Please check your facts and avoid posting made-up error messages that can easily be mistaken for actual ones.
- groovy2shoes 10y agoMy example wasn't meant to be in Common Lisp, just a nebulous "Lisp" dialect. See my response to the sibling here: https://news.ycombinator.com/item?id=13223290 https://news.ycombinator.com/item?id=13223290 I'm not trying to be critical of CL. I thoroughly enjoy working in CL. I'm just trying to clear up some confusion about what it means for a macro to be hygienic, that's all.
- junke 10y ago> My example wasn't meant to be in Common Lisp, just a nebulous "Lisp" dialect. And how can I believe you? this is just too late. > I'm just trying to clear up some confusion [...] You were spreading confusion by using a dialect of Lisp known only by you, that looked exactly like CL, without giving proper warnings. > I'm not trying to be critical of CL. I thoroughly enjoy working in CL. Fine, but this would have been the same if you used a nebulous "Scheme" without saying it so.
- groovy2shoes 10y ago> And how can I believe you? this is just too late. Huh? > You were spreading confusion by using a dialect of Lisp known only by you, that looked exactly like CL, without giving proper warnings. It's a hypothetical example meant to illustrate an aspect of macro hygiene. Again, it's not a criticism of CL. Also, it's not "a dialect of Lisp known only by me". It happens to be EuLisp, which is what I've been working with lately, and I chose it because it was designed as a mix between CL and Scheme (and Le-Lisp, RIP) and I figured that, as such, it would be accessible to both Lispers and Schemers. Apparently, I was wrong. > Fine, but this would have been the same if you used a nebulous "Scheme" without saying it so. The specific language was irrelevant to my point. Only the semantics of defmacro and gensym were relevant. EDIT - fixed a quote and some formatting
- kazinator 10y agoOn that last point, you give the semantics of defmacro as defining "a function that receives an s-expression, manually deconstructs and transforms the s-expression". You then exemplify that with (defmacro hypotenuse (x y) ...) which features automatic destructuring that pulls out x and y. The macro needs to do no further manual destructuring on these arguments.
- groovy2shoes 10y agoYou're right. I was thinking about Scheme when I wrote part of that comment, EuLisp in another part, Common Lisp in another, Le-Lisp in yet another, and my writing wound up being pretty muddled. I apologize for the confusion. I need to work on improving the clarity of my communication. Part of the problem is that I view comments on the Web very casually, a conversation, but that's not really the right way to approach it due to the differences in format. Anyway, thanks. P.S., I was playing with TXR a bit last week after you mentioned it in another thread on here somewhere. After I got to the web site, I recognized it and recalled playing with it a tiny bit quite some time ago (at least a year ago, possibly much longer). Anyway, it's really neat. If I get some spare time sometime soon, I'm going to try and pick it up a bit more because it seems like the kind of thing that will come in very handy at the command line. The ideas in TXR seem really novel to me. Did you come up with that form of pattern language, or did you nab it from somewhere else? The closest thing I can think of is SNOBOL, but TXR is much nicer to use than SNOBOL.