help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How to improve the readability of (any) LISP or any highlevel functi


From: LanX
Subject: Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?
Date: Sat, 1 Jan 2011 19:45:43 -0800 (PST)
User-agent: G2/1.0

> On Jan 1, 11:08 am, Nathan <address@hidden> wrote:
> > Matz himself admitted that “...Ruby is a bad rip-off of Lisp... But it
> > is nicer to ordinary people.”

Matz himself admitted in the earliest sources that Ruby is basically
Perl's semantics melted with Smalltalk's OOP syntax. All influences
from LISP come via Perl and many things criticized in Perl derive from
Larry's dedication to stay close to LISP in contrast to Guido who
breaks a lot in Python, e.g limiting lambdas to single expressions.

For sure Perl's scoping rules are much closer to eLISP's.

So in order to emulate eLISP I would rather chose a Perl or JavaScript
1.7 (with the additional "let"-command) but with the need of extra
macro functionality.

The problem are rather the datatypes which are far more static in
eLISP,
i.e.
1. no autocasting eLisp
2. hashes and arrays have only fixed length in eLisp
3. OTOH linked linked lists are not a  native type in most mainstream
languages.

> How would you code this simple list compression problem in Ruby:
>
> 1.08 (**) Eliminate consecutive duplicates of list elements.
>     If a list contains repeated elements they should be replaced with
> a single copy of the element. The order of the elements should not be
> changed.
>
>     Example:
>     ?- compress([a,a,a,a,b,c,c,a,a,d,e,e,e,e],X).
>     X = [a,b,c,a,d,e]
>

in Perl:
  DB<1>  my $l; print  grep { $l = $_  if  $_ ne $l }
(a,a,a,a,b,c,c,a,a,d,e,e,e,e);
abcade

from 5.10 one can use feature "state" to avoid an extra scope to make
$l lexical.

or define an explicit compress function:

  DB<2> sub compress { my $l;  grep { $l = $_  if  $_ ne $l }  @_ }

  DB<3> print compress(a,a,a,a,b,c,c,a,a,d,e,e,e,e);
abcade

(Nota bene, no explicit return needed like in LISP)

I suppose one can translate those approaches directly to Ruby, Python
or PHP. Newer JS versions call "grep" rather "filter" like in Python.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]