* Re: when you gotta have a variable value for a symbol name
[not found] <mailman.5935.1406151450.1147.help-gnu-emacs@gnu.org>
@ 2014-07-23 23:24 ` Emanuel Berg
0 siblings, 0 replies; 7+ messages in thread
From: Emanuel Berg @ 2014-07-23 23:24 UTC (permalink / raw)
To: help-gnu-emacs
"Buchs, Kevin J." <buchs.kevin@mayo.edu> writes:
> I want to evaluate (kmacro-name-last-macro variable),
> where I want the value of "variable" passed as the
> symbol name. Despite years of trying, I don't think I
> ever really conceptually "got" the distinction
> between symbols and variables and that seems to be
> critical here.
Good question. In books on programming when they
mention Lisp in one paragraph they always say it came
out of a crazy mind. No, it came out of the push for AI
in the US in the 50s (probably with the cold war in
mind and everything). I thought that "AI" referred to
the data/code blend that can make a function rearrange
another function like any other list of data, perhaps
swapping a pair of operands around a binary operator
and reinsert the modified function in a pool of
competing functions, to see what first morphs into a
function that can solve some task... And more, the Lisp
reliance on the list data structure, that can be
nested, and searched, as so much of the AI applications
revolve around searching trees according to probability
calculations... But they (the books) also usually say
Lisp is about "symbolic manipulation". Is that
literally manipulating symbols? Drawing on the
dynamic/lexical scope discussion the other day, symbols
would then be dynamic scope as the function would act
on the existing symbol. Variables would be the lexical
scope or the traditional programming approach of using
variables to build programs (and not the other way
around, to build programs to juggle around with
symbols). I guess almost all ordinary Elisping isn't
anything uncommon like that, just to have Emacs
automatize and do things certain ways, nothing fancy
from a theory/science point of view.
--
underground experts united
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <mailman.5972.1406239064.1147.help-gnu-emacs@gnu.org>]
* when you gotta have a variable value for a symbol name
@ 2014-07-23 21:37 Buchs, Kevin J.
2014-07-23 22:02 ` Drew Adams
[not found] ` <mailman.5936.1406152985.1147.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 7+ messages in thread
From: Buchs, Kevin J. @ 2014-07-23 21:37 UTC (permalink / raw)
To: help-gnu-emacs
I want to evaluate (kmacro-name-last-macro variable), where I want the
value of "variable" passed as the symbol name. Despite years of trying,
I don't think I ever really conceptually "got" the distinction between
symbols and variables and that seems to be critical here. I'm working
with the code below, but it is not suceeding in naming the macros (no
error messages, however). Of course (kmacro-name-last-macro 'my-macro)
works just fine.
--
Kevin Buchs Research Computer Services Phone: 507-538-5459
Mayo Clinic 200 1st. St SW Rochester, MN 55905
http://mayoclinic.org http://facebook.com/MayoClinic http://youtube.com/MayoClinic http://twitter.com/MayoClinic
(defun name-my-macro-sequentially ()
"Names the last recorded macro as my-macro#, where # is a number sequentially incremented"
(interactive)
(unless (boundp 'my-macro-counter) (setq my-macro-counter 0))
(setq my-macro-counter (1+ my-macro-counter))
(let ((macro-name (format "my-macro-%d" my-macro-counter)))
(kmacro-name-last-macro (make-symbol macro-name))
(message "named keyboard macro %s" macro-name)))
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: when you gotta have a variable value for a symbol name
2014-07-23 21:37 Buchs, Kevin J.
@ 2014-07-23 22:02 ` Drew Adams
[not found] ` <(message>
2014-07-24 21:57 ` Robert Thorpe
[not found] ` <mailman.5936.1406152985.1147.help-gnu-emacs@gnu.org>
1 sibling, 2 replies; 7+ messages in thread
From: Drew Adams @ 2014-07-23 22:02 UTC (permalink / raw)
To: Buchs, Kevin J., help-gnu-emacs
> I want to evaluate (kmacro-name-last-macro variable), where I want the
> value of "variable" passed as the symbol name. Despite years of trying,
> I don't think I ever really conceptually "got" the distinction between
> symbols and variables and that seems to be critical here. I'm working
> with the code below, but it is not suceeding in naming the macros (no
> error messages, however). Of course (kmacro-name-last-macro 'my-macro)
> works just fine.
>
> (defun name-my-macro-sequentially ()
> "Names the last recorded macro as my-macro#, where # is a number
> sequentially incremented"
> (interactive)
> (unless (boundp 'my-macro-counter) (setq my-macro-counter 0))
> (setq my-macro-counter (1+ my-macro-counter))
> (let ((macro-name (format "my-macro-%d" my-macro-counter)))
> (kmacro-name-last-macro (make-symbol macro-name))
^^^^^^^^^^^
> (message "named keyboard macro %s" macro-name)))
Change `make-symbol' to `intern' and you're good to go. `make-symbol'
returns an uninterned symbol.
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <(message>]
* Re: when you gotta have a variable value for a symbol name
2014-07-23 22:02 ` Drew Adams
[not found] ` <(message>
@ 2014-07-24 21:57 ` Robert Thorpe
2014-07-25 0:06 ` Drew Adams
1 sibling, 1 reply; 7+ messages in thread
From: Robert Thorpe @ 2014-07-24 21:57 UTC (permalink / raw)
To: Drew Adams; +Cc: buchs.kevin, help-gnu-emacs
Drew Adams <drew.adams@oracle.com> writes:
>> I want to evaluate (kmacro-name-last-macro variable), where I want the
>> value of "variable" passed as the symbol name. Despite years of trying,
>> I don't think I ever really conceptually "got" the distinction between
>> symbols and variables and that seems to be critical here. I'm working
>> with the code below, but it is not suceeding in naming the macros (no
>> error messages, however). Of course (kmacro-name-last-macro 'my-macro)
>> works just fine.
Lisp is like the insides of a compiler. There's a big hash-map, the
obarray, which is the symbol-table. It stores strings along with some
information about them. These strings are "symbols". There are three
pieces of information: the symbol's value as a variable, the symbols
value as a function and a property list. An interned symbol is one that
is an entry in the obarray (there can be multiple obarrays though that
feature isn't used much). An uninterned symbol is one that sits by
itself, it has the same parts as usual: string, function entry, variable
entry and plist, but it's not attached to an obarray. If we have a
function call: (foo bar 'baz) then lisp treats each of these symbols
differently. It finds the function slot for foo because that's the
first symbol, it finds the variable slot for bar because it's not first.
Finally, 'baz returns the symbol itself. To be more careful: (quote
baz) returns a list containing the symbol, which evaluates to the
symbol.
(info "(elisp) Symbols")
BR,
Robert Thorpe
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <mailman.5936.1406152985.1147.help-gnu-emacs@gnu.org>]
* Re: when you gotta have a variable value for a symbol name
[not found] ` <mailman.5936.1406152985.1147.help-gnu-emacs@gnu.org>
@ 2014-07-23 22:12 ` Pascal J. Bourguignon
0 siblings, 0 replies; 7+ messages in thread
From: Pascal J. Bourguignon @ 2014-07-23 22:12 UTC (permalink / raw)
To: help-gnu-emacs
Drew Adams <drew.adams@oracle.com> writes:
>> I want to evaluate (kmacro-name-last-macro variable), where I want the
>> value of "variable" passed as the symbol name. Despite years of trying,
>> I don't think I ever really conceptually "got" the distinction between
>> symbols and variables and that seems to be critical here. I'm working
>> with the code below, but it is not suceeding in naming the macros (no
>> error messages, however). Of course (kmacro-name-last-macro 'my-macro)
>> works just fine.
>>
>> (defun name-my-macro-sequentially ()
>> "Names the last recorded macro as my-macro#, where # is a number
>> sequentially incremented"
>> (interactive)
>> (unless (boundp 'my-macro-counter) (setq my-macro-counter 0))
>> (setq my-macro-counter (1+ my-macro-counter))
>> (let ((macro-name (format "my-macro-%d" my-macro-counter)))
>> (kmacro-name-last-macro (make-symbol macro-name))
> ^^^^^^^^^^^
>> (message "named keyboard macro %s" macro-name)))
>
> Change `make-symbol' to `intern' and you're good to go. `make-symbol'
> returns an uninterned symbol.
And use:
(defvar my-macro-counter 0)
(defun …
)
instead of:
(defun …
…
(unless (boundp 'my-macro-counter) (setq my-macro-counter 0))
…)
--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-07-25 0:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.5935.1406151450.1147.help-gnu-emacs@gnu.org>
2014-07-23 23:24 ` when you gotta have a variable value for a symbol name Emanuel Berg
[not found] <mailman.5972.1406239064.1147.help-gnu-emacs@gnu.org>
2014-07-24 22:22 ` Emanuel Berg
2014-07-23 21:37 Buchs, Kevin J.
2014-07-23 22:02 ` Drew Adams
[not found] ` <(message>
[not found] ` <from>
[not found] ` <Drew>
[not found] ` <Adams>
[not found] ` <on>
[not found] ` <Wed>
[not found] ` <23>
[not found] ` <Jul>
[not found] ` <2014>
[not found] ` <15:02:38>
[not found] ` <-0700>
2014-07-24 21:57 ` Robert Thorpe
2014-07-25 0:06 ` Drew Adams
[not found] ` <mailman.5936.1406152985.1147.help-gnu-emacs@gnu.org>
2014-07-23 22:12 ` Pascal J. Bourguignon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).