newLISP Fan Club

Forum => Anything else we might add? => Topic started by: Cyril on February 06, 2008, 05:54:24 PM

Title: To read an expression from a file or string?
Post by: Cyril on February 06, 2008, 05:54:24 PM
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?
Title:
Post by: Jeff on February 06, 2008, 06:24:22 PM
read-file
Title:
Post by: Cyril on February 06, 2008, 07:34:35 PM
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) ?
Title:
Post by: HPW on February 06, 2008, 10:29:33 PM

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


But so you have the same as a 'load'.
Title:
Post by: Jeff on February 07, 2008, 04:44:37 AM
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.
Title:
Post by: Dmi on February 07, 2008, 05:25:09 AM
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 ;-)
Title:
Post by: Lutz on February 07, 2008, 06:23:44 AM
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
Title:
Post by: Dmi on February 07, 2008, 06:35:07 AM
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?
Title:
Post by: Jeff on February 07, 2008, 07:11:56 AM
I would definitely like access to that, too, Lutz.  There are dozens of uses.  Writing newnewLISP, for example :)
Title:
Post by: m35 on February 07, 2008, 09:57:56 AM
I wanted to do the same thing for the 'newLINT (//http)' 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.
Title:
Post by: Cyril on February 07, 2008, 02:37:06 PM
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.