[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Source filters
Much as I hate to compliment perl ;-) ;-), that's pretty effing amazing. I
wonder what the original motivation was for this feature. I can't imagine
there was that much call for latin (or pig-latin, or esperanto...). In
some ways this takes the macro concept to its logical extreme (although I
doubt it's as easy to manipulate code as it is in lisp/scheme macros).
Do any other languages have this feature?
Mike
> From: Jasvir Nagra <jas@cs.arizona.edu>
> Date: Wed, 21 May 2003 09:42:59 -0700
>
> I am lowly perl minion and this is a question better addressed by the
> gods, however:
>
> Perl has source filters. This is a special kind of filter that
> modifies the source after it is loaded into memory and before it
> reaches the parser. One can do whatever translation one wishes
> provided the translation results in correct perl code.
>
> So modules such as the following exist:
>
> use Filter::cpp;
> #define FOO 1
> #ifdef FOO
> print "fooing";
> #else
> print "baring";
> #endif
>
> or
>
> use Rot13;
> cevag "uryyb serq\a" ;
>
> A source filter that provides a scheme like syntax for perl would be
> straightforward if one does not in fact exist already.
>
> /jas
>
> Michael Vanier <mvanier@cs.caltech.edu> writes:
>
> > I'm glad you brought this up. For those of us who aren't perl gurus, can
> > you please explain to us in as little space as possible how the hell perl
> > does this kind of thing? Is the perl lexer/parser dynamically hackable or
> > something? Would it be possible to write a scheme-like syntax for perl if
> > one was so inclined? If not, where are the lines drawn?
> >
> > I'm wondering if perl has the same kind of power as, say, ocamlp4 gives to
> > ocaml, or if it's doing something completely different.
> >
> > Really curious,
> >
> > Mike
> >
> >> From: Jasvir Nagra <jas@cs.arizona.edu>
> >> Date: Wed, 21 May 2003 08:43:22 -0700
> >>
> >> Dan Sugalski <dan@sidhe.org> writes:
> >>
> >> > 2) If the parser saw 1 + three in the code stream it wouldn't do the
> >> > math, so I'd generally assume that 1 + "three" wouldn't either.
> >> >
> >> > Both statements are language-local--I wouldn't be surprised to find a
> >> > language that allowed "three" either as a string constant or bareword
> >> > to translate to the number three. I'd expect it wouldn't be as useful
> >>
> >> #!/usr/bin/perl -l
> >>
> >> use Lingua::Romana::Perligata;
> >>
> >> addementum tres tum 1 egresso scribe.
> >> addementum tres tum unum egresso scribe.
> >> addementum 3 tum 1 egresso scribe.
> >>
> >> --
> >> Jasvir Nagra
> >> http://www.cs.auckland.ac.nz/~jas
> >>
> >
>
> --
> Jasvir Nagra
> http://www.cs.auckland.ac.nz/~jas
>