Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Lord, what fools these mortals be! -- William Shakespeare, "A Midsummer-Night's Dream"


comp / comp.lang.lisp / Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )

SubjectAuthor
* Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )HenHanna
+* Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )Daniel Cerqueira
|`* Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )Lawrence D'Oliveiro
| `- Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )HenHanna
`* Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )Sebastian Wells
 `- Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )Lawrence D'Oliveiro

1
Subject: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )
From: HenHanna
Newsgroups: comp.lang.python, comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Fri, 31 May 2024 04:47 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.python,comp.lang.lisp,comp.lang.scheme
Subject: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in
Python )
Date: Thu, 30 May 2024 21:47:14 -0700
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <v3bkoj$23bck$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 31 May 2024 06:47:15 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="512d4da52372882ea9ed0f897c428d2f";
logging-data="2207124"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5ulEZE+GyhAhJ2d2KszZcSeWnKsObUNI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ZcI1L5Avh6iv8URcX8Qy2CRJuG8=
Content-Language: en-US
View all headers

;;; Pls tell me about little tricks you use in Python or Lisp.

[('the', 36225), ('and', 17551), ('of', 16759), ('i', 16696), ('a',
15816), ('to', 15722), ('that', 11252), ('in', 10743), ('it', 10687)]

((the 36225) (and 17551) (of 16759) (i 16696) (a 15816) (to 15722) (that
11252) (in 10743) (it 10687))

i think the latter is easier-to-read, so i use this code
(by Peter Norvig)

def lispstr(exp):
# "Convert a Python object back into a Lisp-readable string."
if isinstance(exp, list):
return '(' + ' '.join(map(lispstr, exp)) + ')'
else:
return str(exp)

def Lprint(x): print(lispstr(x))

Subject: Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )
From: Daniel Cerqueira
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Fri, 31 May 2024 12:58 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: dan.list@lispclub.com (Daniel Cerqueira)
Newsgroups: comp.lang.lisp
Subject: Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )
Date: Fri, 31 May 2024 13:58:07 +0100
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <87v82ugmu8.fsf@lispclub.com>
References: <v3bkoj$23bck$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Fri, 31 May 2024 14:58:09 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2321ee7ea5e4a8b1af588046ac3b6676";
logging-data="2355361"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XNkYivWYRP0IPANUiBT9pFaiSzmfmFFw="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:bhtAY+mDlgGErki+KrPX6YQi4Qs=
sha1:WZyA+sZUmnxMhmaE9H3PESmM24A=
View all headers

HenHanna <HenHanna@devnull.tb> writes:

> ;;; Pls tell me about little tricks you use in Python or Lisp.
> (...)
>
> def lispstr(exp):
> # "Convert a Python object back into a Lisp-readable string."
> if isinstance(exp, list):
> return '(' + ' '.join(map(lispstr, exp)) + ')'
> else:
> return str(exp)
>
> def Lprint(x): print(lispstr(x))

This is a LISP group. Mind I say that Python is not a LISP, in case your
intelligence haven't reached there yet.

Don't post code in unrelated languages. Only LISP code is relevant here.

Subject: Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )
From: Lawrence D'Oliv
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sat, 1 Jun 2024 00:24 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.lisp
Subject: Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in
Python )
Date: Sat, 1 Jun 2024 00:24:36 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <v3dpo4$2epqd$3@dont-email.me>
References: <v3bkoj$23bck$1@dont-email.me> <87v82ugmu8.fsf@lispclub.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 01 Jun 2024 02:24:37 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="f72ad8a79c807b0fc25fcf9a33f846de";
logging-data="2582349"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18v4nJnVT2UCUxm7TOIcWQT"
User-Agent: Pan/0.158 (Avdiivka; )
Cancel-Lock: sha1:e2C9G9qejmvb3ZvxBv2CMwqbyTk=
View all headers

On Fri, 31 May 2024 13:58:07 +0100, Daniel Cerqueira wrote:

> Mind I say that Python is not a LISP, in case your
> intelligence haven't reached there yet.

Some of us do mind.

Subject: Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )
From: HenHanna
Newsgroups: comp.lang.lisp, sci.lang
Organization: A noiseless patient Spider
Date: Thu, 6 Jun 2024 20:32 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.lisp,sci.lang
Subject: Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in
Python )
Date: Thu, 6 Jun 2024 13:32:57 -0700
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <v3t6dp$1ljta$1@dont-email.me>
References: <v3bkoj$23bck$1@dont-email.me> <87v82ugmu8.fsf@lispclub.com>
<v3dpo4$2epqd$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 06 Jun 2024 22:32:57 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="bc23964f43fff663a93a4a6fea2a4f6c";
logging-data="1757098"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ylOaHCp/mEiLWUKoJKtPmRzB0KMoBbCo="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:kDGlJGE17c1aucF0sdZlrM6k5PM=
In-Reply-To: <v3dpo4$2epqd$3@dont-email.me>
Content-Language: en-US
View all headers

On 5/31/2024 5:24 PM, Lawrence D'Oliveiro wrote:
> On Fri, 31 May 2024 13:58:07 +0100, Daniel Cerqueira wrote:
>
>> Mind I say that Python is not a LISP, in case your
>> intelligence haven't reached there yet.
>
> Some of us do mind.

Python is not Lisp, but

( Lisp-style printing ( of lists and strings (etc.) ) in Python )

is Lisp

Subject: Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )
From: Sebastian Wells
Newsgroups: comp.lang.python, comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 05:38 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: sebastian@here.com.invalid (Sebastian Wells)
Newsgroups: comp.lang.python,comp.lang.lisp,comp.lang.scheme
Subject: Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in
Python )
Date: Mon, 24 Jun 2024 05:38:07 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <v5b0nv$7182$2@dont-email.me>
References: <v3bkoj$23bck$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 24 Jun 2024 07:38:09 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2787d93bb44b66d3fe4dceb9b5d2d9b9";
logging-data="230658"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19nWfyBbmhvNTwzRsJsvg95qXPQLQZoZpY="
User-Agent: Pan/0.154 (Izium; 517acf4)
Cancel-Lock: sha1:rY5rTbmDHhSEpwBJxSIfuFOT+1A=
View all headers

On Thu, 30 May 2024 21:47:14 -0700, HenHanna wrote:

> ;;; Pls tell me about little tricks you use in Python or Lisp.
>
>
> [('the', 36225), ('and', 17551), ('of', 16759), ('i', 16696), ('a',
> 15816), ('to', 15722), ('that', 11252), ('in', 10743), ('it', 10687)]
>
> ((the 36225) (and 17551) (of 16759) (i 16696) (a 15816) (to 15722) (that
> 11252) (in 10743) (it 10687))
>

The direct Lispification of the original expression would probably be
something like this:

#(#("the" 36225) #("and" 17551) #("of" 16759)
#("i" 16696) #("a" 15816))

...etc, taking into account that Python "lists" are really
arrays, and there's no real Lisp equivalent to tuples,
but they're essentially arrays also. And there's a distinction
between strings and symbols in Lisp that could be approximated
in Python by defining an empty class for each desired symbol.
But since strings are used in the Python example, they should
be used in the Lisp one, too.

That written, there's not much benefit in doing this in a Python
program, and you actually lose one of the advantages you started
out with: Like Lisp, the Python syntax is readable Python. Unlike
Lisp, there's no reader that will give you the original structure
from its string representation without having to also evaluate it
as code. Lispifying it doesn't bring that advantage unless you
also implement a reader, and even then you might be better off
convincing some insider to endorse a Python analogue to JSON. But
that insider would probably tell you to use JSON, ignoring
the lack of distinct array/tuple types in JSON, or he'd tell you
to use Pickle, ignoring the fact that it's a binary format.

Norvig was coping big time. He even called Python an "acceptable"
compromise between what Lisp delivers and whatever it is that's
supposed to be good about Python that it didn't directly copy
from Lisp.

Subject: Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )
From: Lawrence D'Oliv
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 05:42 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in
Python )
Date: Mon, 24 Jun 2024 05:42:56 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <v5b10v$pqf9$1@dont-email.me>
References: <v3bkoj$23bck$1@dont-email.me> <v5b0nv$7182$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 24 Jun 2024 07:42:56 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="3048fea01d51f9337586ac8e02824e6c";
logging-data="846313"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/bnC0OyY21ppsAZ4YnOUyE"
User-Agent: Pan/0.158 (Avdiivka; )
Cancel-Lock: sha1:1ElHD1KcZ4/yWke/QgOJqSiPSQM=
View all headers

On Mon, 24 Jun 2024 05:38:07 -0000 (UTC), Sebastian Wells wrote:

> Unlike Lisp,
> there's no reader that will give you the original structure from its
> string representation without having to also evaluate it as code.

If that means what I think it means, it’s wrong. You can indeed compile
Python source to AST form without going all the way to bytecode.

1

rocksolid light 0.9.8
clearnet tor