----------------------------------------------------------------------------------
@MSGID: <87a5u0gevh.fsf@gmail.com> 3768d8a7
@REPLY:
9920c478
@REPLYADDR steve <sgonedes1977@gmail.com>
@REPLYTO 2:5075/128 steve
@CHRS: CP866 2
@RFC: 1 0
@RFC-References:
@RFC-Message-ID: <87a5u0gevh.fsf@gmail.com>
@TZUTC: -0400
@PID: Gnus/5.13 (Gnus v5.13) Emacs/28.2
(gnu/linux)
@TID: FIDOGATE-5.12-ge4e8b94
albert@cherry.(none) (albert) writes:
> The explanations about the usage of gensym are clear,
> how your are supposed to used them.
> The theoretical background however is far from it.
gensym is used in macros. like mkstemp in C.
> (let* (aaa (gensym)) .. aaa .. )
>
> In the context `` .. aaa .. `` `aaa is obviously a symbol.
> The interesting question is what value is aaa coupled to due to
> the environment (aaa (gensym))?
> Apparently aaa must be evaluated before it is any use.
> However subsequently you see
> (let* (aaa (rest whatever)) ... )
> What is disturbing to me is that let* only allows symbols into the
> position of aaa and normally the coupling of aaa hides previous usage.
> I have the following lisp type of objects:
> symbols lists numbers strings arrays hashes normal-function
> special-functions booleans
> and more MAL oddballs:
> nil key atom
>
> Nothing seems an appropriate type for `aaa.
>
> Example studied:
>
> (defmacro! or
> (fn* (& xs)
> (if (empty? xs)
> nil
> (if (= 1 (count xs))
> (first xs)
> (let* (condvar (gensym))
> `(let* (~condvar ~(first xs))
;; try (let* (,~condvar ~(first xs))
> (if ~condvar ~condvar (or ~@(rest xs)))))))))
instead of using macro names with thisvar_ as you would use in C use
gensym. here is a small example.
(defmacro dostring ((var str &optional (return-value nil)) &body forms)
(declare (string str))
`(loop for ,var of-type character across (the string ,str)
do (locally ,@forms) finally (return ,return-value)))
(defmacro do-string-codes ((var string &optional return-value) &body forms)
(let ((ch-var (gensym "CHARACTER")))
`(dostring (,ch-var ,string ,return-value)
(let ((,var (char-code ,ch-var)))
,@forms))))
=> (dostring (chr "hello world")
(print chr))
#\\h
#
#\\l
#\\l
#\\o
#\\
#\\w
#\\o
#
#\\l
#\\d
NIL
macroexpand
(LOOP FOR CHR OF-TYPE CHARACTER ACROSS (THE STRING "hello world")
DO (LOCALLY (PRINT CHR))
FINALLY (RETURN NIL))
sorry for the convoluted code - this is what I have..
usually make-symbol is used; gensym is never eq.
--- Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
* Origin: usenet.network (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5058/104 5075/128
@PATH: 5075/128 5020/1042 4441