Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using let

0 views
Skip to first unread message

lpillman

unread,
Jun 13, 2001, 3:32:27 PM6/13/01
to
i'm a lisp newbie, so bear with me. i've read a lot of web
pages, manuals, etc. and must be missing someting VERY
simple.

i can't get the following to work (adding font-lock
support for an emacs mode and i need %size, $page, etc):

(defvar mgp-font-lock-keywords
(let (keywords '("size\\|page"))
(list (concat "\\%\\(" keywords "\\)")
1 'font-lock-keyword-face)
)
"keywords for mgp-font-lock")

thanks,

- brett

Barry Margolin

unread,
Jun 13, 2001, 3:44:15 PM6/13/01
to

The syntax of LET is:

(let ((<var1> <val1>)
(<var2> <val2>)
...)
<body>)

Compare this syntax to what you wrote, paying careful attention to the
number of parentheses.

(For the pedants out there, I know I've left out a special case; once he's
mastered the basic syntax, we can let him in on the shortcuts.)

--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

lpillman

unread,
Jun 13, 2001, 3:55:12 PM6/13/01
to
Barry Margolin wrote:
>
> In article <3B27BFCB...@best.com>, lpillman <beld...@best.com> wrote:
> >i'm a lisp newbie, so bear with me. i've read a lot of web
> >pages, manuals, etc. and must be missing someting VERY
> >simple.
> >
> >i can't get the following to work (adding font-lock
> >support for an emacs mode and i need %size, $page, etc):
> >
> >(defvar mgp-font-lock-keywords
> > (let (keywords '("size\\|page"))
> > (list (concat "\\%\\(" keywords "\\)")
> > 1 'font-lock-keyword-face)
> > )
> >"keywords for mgp-font-lock")
>
> The syntax of LET is:
>
> (let ((<var1> <val1>)
> (<var2> <val2>)
> ...)
> <body>)
>
> Compare this syntax to what you wrote, paying careful attention to the
> number of parentheses.

okay, but even if i surround my one variable mapping like so (i didn't
think you needed the surrounding () for only one mapping) it still
doesn't work.

(defvar mgp-font-lock-keywords
(let (

Christopher Stacy

unread,
Jun 13, 2001, 4:51:29 PM6/13/01
to
Look at Barry's example again (you didn't do all that he suggested).

Barry Margolin

unread,
Jun 14, 2001, 10:55:20 AM6/14/01
to
In article <3B27C51F...@best.com>, lpillman <beld...@best.com> wrote:
>Barry Margolin wrote:
>>
>> In article <3B27BFCB...@best.com>, lpillman <beld...@best.com> wrote:
>> >i'm a lisp newbie, so bear with me. i've read a lot of web
>> >pages, manuals, etc. and must be missing someting VERY
>> >simple.
>> >
>> >i can't get the following to work (adding font-lock
>> >support for an emacs mode and i need %size, $page, etc):
>> >
>> >(defvar mgp-font-lock-keywords
>> > (let (keywords '("size\\|page"))
>> > (list (concat "\\%\\(" keywords "\\)")
>> > 1 'font-lock-keyword-face)
>> > )
>> >"keywords for mgp-font-lock")
>>
>> The syntax of LET is:
>>
>> (let ((<var1> <val1>)
>> (<var2> <val2>)
>> ...)
>> <body>)
>>
>> Compare this syntax to what you wrote, paying careful attention to the
>> number of parentheses.
>
>okay, but even if i surround my one variable mapping like so (i didn't
>think you needed the surrounding () for only one mapping) it still
>doesn't work.

The reason why you need the extra () for one binding is because of the
special case that I omitted. Instead of (<varN> <valN>) you're allowed to
write just <varN>, and it's a shortcut for (<varN> nil). So your original
code was actually binding *two* variables; it was equivalent to:

(let ((keywords nil)
(quote ("size\\|page")))
...)

>(defvar mgp-font-lock-keywords
> (let (
> (keywords '("size\\|page"))
> (list (concat "\\%\\(" keywords "\\)")
> 1 'font-lock-keyword-face)
> )
> )
>"keywords for mgp-font-lock")

Look at where you have LIST now. It's in the place where the second
variable binding would be, rather than the body.

P.S. Please see any Lisp textbook for the accepted way to lay out
indentation and parentheses. A line should never end with an open
parenthesis or begin with a close paren.

0 new messages