To read an expression from a file or string?

Started by Cyril, February 06, 2008, 05:54:24 PM

Previous topic - Next topic

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

#1
read-file
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

Cyril

#2
Quote from: "Jeff"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

#3

> (eval-string "'(a b c)")
(a b c)


But so you have the same as a 'load'.
Hans-Peter

Jeff

#4
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...



http://artfulcode.net\">Artful code

Dmi

#5
Hi, Cyrill!



Look into http://en.feautec.pp.ru">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

#6
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

#7
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

#8
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...



http://artfulcode.net\">Artful code

m35

#9
I wanted to do the same thing for the 'http://www.alh.net/newlisp/phpbb/viewtopic.php?p=9217&highlight=#9217">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
(eval-string (append "(quote " (read-file "file.lsp") ")"))might do the trick. I never actually tested it though.

Cyril

#10
Quote from: "Dmi"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!