To read an expression from a file or string?

For the Compleat Fan
Locked
Cyril
Posts: 183
Joined: Tue Oct 30, 2007 6:27 pm
Location: Moscow, Russia
Contact:

To read an expression from a file or string?

Post by Cyril »

I feel myself dumb (as usual), but is it a way to read an newlisp expression from file or string (buffer), not evaluating it? Something like read in both Common Lisp and Scheme?
With newLISP you can grow your lists from the right side!

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

read-file
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Cyril
Posts: 183
Joined: Tue Oct 30, 2007 6:27 pm
Location: Moscow, Russia
Contact:

Post by Cyril »

Jeff wrote:read-file
read-file reads file as a string, not as an expression. I mean, if you file contains a line "(a b c)", or you have a string with the same content, how do you read or convert it to the list (a b c) ?
With newLISP you can grow your lists from the right side!

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Code: Select all

> (eval-string "'(a b c)")
(a b c)
But so you have the same as a 'load'.
Hans-Peter

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

Ah, you want to read the string in as a quoted expression. No, not that I know of. Anything that would interpret the block would evaluate it.
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

Hi, Cyrill!

Look into http://en.feautec.pp.ru around newlisp console (nlc) project. There is some sort of a parser. Feel free to ask questions.

P.S. But, I think it would be cool to have a newlisp hardcoded engine (I suspect - a link to some existing internal function will be sufficient ;-)
WBR, Dmi

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Internally such a function already exists. It reads one top-level term or s-expression from a file or string and returns. It would be easy to expose this function in the newLISP API.

The question is: what do you want to do with it? Perhaps there is a different way to achieve the same?

Lutz

Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

Hi, Lutz!

My needs was: code analyze/edit, reformat/reindent, sanitize (wrapping the string with (quote ) before eval-string is not a way in common).

What about Cyrill?
WBR, Dmi

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

I would definitely like access to that, too, Lutz. There are dozens of uses. Writing newnewLISP, for example :)
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

m35
Posts: 171
Joined: Wed Feb 14, 2007 12:54 pm

Post by m35 »

I wanted to do the same thing for the 'newLINT' idea--load a .lsp file as a list instead of executing it. Long after I gave up on making it, it occurred to me that perhaps doing

Code: Select all

(eval-string (append "(quote " (read-file "file.lsp") ")"))
might do the trick. I never actually tested it though.

Cyril
Posts: 183
Joined: Tue Oct 30, 2007 6:27 pm
Location: Moscow, Russia
Contact:

Post by Cyril »

Dmi wrote:My needs was: code analyze/edit, reformat/reindent, sanitize (wrapping the string with (quote ) before eval-string is not a way in common).

What about Cyrill?
In fact the same: any processing of the newLISP programs in newLISP itself. My idea was to implement some experimental preprocessor: that one was probably not worth doing, but there are others.
With newLISP you can grow your lists from the right side!

Locked