[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: text processing as *the* problem



Your example switch is something that comes up fairly often.
In any Lisp you can easily write a macro for it; here's CL:

(defmacro casequal (val &rest clauses)
  (let ((g (gensym)))
    `(let ((,g ,val))
       (cond ,@(mapcar #'(lambda (cl)
                           `(,(if (eql (car cl) t)
                                  t
                                  `(equal ,g ,(car cl)))
                             ,@(cdr cl)))
                       clauses)))))

> (casequal "foo"
    ("foo" 1)
    ("bar" 2))
1

Back when Beating the Averages was on slashdot, I remember
someone saying that it was bogus to claim that macros had 
given us a competitive advantage, because there was no reason 
you needed to define new syntactic forms to make an online 
store builder.  In fact, just the opposite is true, as you're 
finding: it's useful to be able to define new syntactic forms 
in any substantial application.

--pg

--- "KELLEHER,KEVIN (Non-HP-Roseville,ex1)" <kevin_kelleher@non.hp.com>
wrote:
> Shriram,
> 
> Thanks to you and all who posted on my question.  I've downloaded
> sgrep,
> which looks like it
> will do a lot of what I want.  Once I saw it, I was surprised that
> I'd never
> heard of it before.
> Someone I work with also mentioned gema, which is a macro processor,
> and I
> think the
> two of them will be a big help.
> 
> The material about parsing and pattern matching in Scheme I will work
> on
> trying to
> understand.  I am still learning it; it is fun.
> 
> What motivated my initial post was the Call for Participation from
> LL1:
> there were a few
> ideas that struck me
> 
>  - the desire to connect the academy and industry
>  - a survey of languages that "sprung up"
> 
> As I said, I am not a language designer - just a programmer.  I've
> been
> programming for a
> little over twelve years, self taught.  Five years ago I took a look
> at the
> MIT Computer Science
> curriculum to see what I was missing, and I think it's this:
> 
>  - functional languages
>  - advanced math
>  - compilers and parsers
> 
> I've been working on the first, and making tentative steps on the
> last - I
> don't have a lot
> of spare time.  But when I do have spare time, or am feeling low, I
> like to
> poke around in
> 
> 	http://directory.google.com/Top/Computers/Programming/Languages/
> 
> And often find myself struggling with problems of text manipulation
> (I know
> this is vague) --
> it is not always XML or HTML -- a case in point from last week:  it
> would be
> so handy if
> C/C++ had something like this:
> 
> 	switch (myVariable) {
> 		case "who":
> 			...
> 			break;
> 
> 		case "what":
> 			...
> 			break;
> 		...
> 	}
> 
> Or for a date utility that I'm working on - it would be nice if it
> were easy
> to read the
> arguments off the command line and figure out which pieces are
> elements of
> dates,
> whether the user wants to add or subtract days from a date or get the
> difference
> between two dates or get a sequence of dates that fit a certain
> criteria
> ("all the
> Fridays in December 1886").
> 
> Now, I am not asking for the solution of any of these problems.
> 
> Maybe Lisp or Scheme can do all the things I want.  I can believe
> that.
> 
> Even if it's so, I have been asking myself, "What would a language
> look like
> that
> would do the things I want to do?"   What sort of commands would I
> *want* to
> write?  What sort of functions would make it easy to do the things I
> want to
> do?
> 
> I haven't come up with a single answer yet.  I was hoping that
> someone has
> been
> looking at this question:  A higher-level approach to dealing with
> text.
> The Icon
> language was suggested, and that also looks promising, interesting,
> and fun.
> It does show that whoever designed it had struggled with the same
> sort of
> problems
> that I do.
> 
> Kevin Kelleher
> 


__________________________________________________
Do You Yahoo!?
Buy the perfect holiday gifts at Yahoo! Shopping.
http://shopping.yahoo.com