How to make newLISP quiet when it starts; start with ()

Q&A's, tips, howto's

How to make newLISP quiet when it starts; start with ()

Postby scottmaccal » Fri May 15, 2009 4:53 pm

Hi all,

When I start newLISP from the shell, I'd like it to be quiet. No newLISP v.9.4.5 on BSD IPv4, execute 'newlisp -h' for more info message.

I would also like newLISP to start with () with the cursor in the middle.

Does newLISP use something similar to a .emacs?

What is the best way to make this modification.
Whether gods exist or not, there is no way to get absolute certainty about ethics. Without absolute certainty, what do we do? We do the best we can. --Richard Stallman
scottmaccal
 
Posts: 20
Joined: Fri Mar 28, 2008 2:12 am

Postby shercipher » Fri May 15, 2009 5:15 pm

You can turn off prompts with the -c option. Don't know how to get a () (I don't think readlines even supports that, emacs probably does). There doesn't seem to be a quiet or suppress option; that needs to be added.
shercipher
 
Posts: 15
Joined: Sun May 10, 2009 3:11 am

Postby Lutz » Fri May 15, 2009 6:00 pm

There are support files for several editors here (including emacs support):

http://www.newlisp.org/index.cgi?Code_Contributions

There are also two functions to write more sophisticated REPL supoort in newLISP iself (newLISP 10.0 or later required):

http://www.newlisp.org/newlisp_manual.html#prompt-event

and here:

http://www.newlisp.org/newlisp_manual.h ... mand-event

The file newlisp-x.x.x/util/nls in the source distribution is a script showing how to use this functions and also includes command-line help. nls tries to combine the BASH shell with a newLISP REPL.

Cormullion from http://unbalanced-parentheses.nfshost.com has shown a few months back, how to build a repl using 'prompt-event' and 'command-event' which handles the entry of multi-line functions.

Last not least: on Mac OS X and other UNIX like OSs there is also support for .inputrc to customize for options from the linked in GNU readline library.
Lutz
 
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Postby cormullion » Fri May 15, 2009 6:08 pm

Lutz wrote:Cormullion from http://unbalanced-parentheses.nfshost.com has shown a few months back, how to build a repl using 'prompt-event' and 'command-event' which handles the entry of multi-line functions.


That has serious problems, so don't use it as is...

Try putting this in ~/.init.lsp:

Code: Select all
(prompt-event (fn () ""))
cormullion
 
Posts: 2037
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W

Postby Lutz » Fri May 15, 2009 6:19 pm

Yes, Cormullion's repl code is more a proof of concept, than a finished program, but worth looking at for some interesting ideas.

And I forgot: there is built-in function name completion for newLISP native functions when hitting the TAB key. Hitting it twice shows all available functions. This is the same kind of support known from the Bash shell. OS X and other UNIXs only.
Lutz
 
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Wow.

Postby scottmaccal » Fri May 15, 2009 7:48 pm

Hi all,

Wow, a flood of responses right away. Thank you!

What I'm really trying to do is have (cursor) after a print.

(print "Input function please ") (cursor)

I would like a function to be called by input without the user having to worry about typing the (). They can just input the function name and press enter.
Whether gods exist or not, there is no way to get absolute certainty about ethics. Without absolute certainty, what do we do? We do the best we can. --Richard Stallman
scottmaccal
 
Posts: 20
Joined: Fri Mar 28, 2008 2:12 am

Postby cormullion » Fri May 15, 2009 9:09 pm

Well, you could put this into ~/.init.lsp:

Code: Select all
(prompt-event (fn () "Input function: "))

(command-event (fn (c)
  (println "you typed " c " so I'm evaluating " (string "(" c ")") )
  (string "(" c ")"))) 


to get this, for example:

Code: Select all
$ newlisp -c
context
you typed context so I'm evaluating (context)
MAIN
+ 2 2
you typed + 2 2 so I'm evaluating (+ 2 2)
4
reverse "aloha"
you typed reverse "aloha" so I'm evaluating (reverse "aloha")
"ahola"
exit
you typed exit so I'm evaluating (exit)
$


but I think it's a really bad idea...! :)
cormullion
 
Posts: 2037
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W

Postby scottmaccal » Sun May 17, 2009 1:05 pm

Hi cormullion,

Thank you for you reply. I will give it a try.
Whether gods exist or not, there is no way to get absolute certainty about ethics. Without absolute certainty, what do we do? We do the best we can. --Richard Stallman
scottmaccal
 
Posts: 20
Joined: Fri Mar 28, 2008 2:12 am

Postby scottmaccal » Wed May 20, 2009 4:42 pm

Hi cormullion,

I tried your suggestions and I couldn't get them to work. Perhaps I am not understanding. Here is some code that I hope is a little clearer.

Code: Select all
(define (main)
  (print "What can I assist you with? ")
  code that will place (cursor) after the question
)


Result of evaluated function main on screen:

What can I do for you? (cursor)
Whether gods exist or not, there is no way to get absolute certainty about ethics. Without absolute certainty, what do we do? We do the best we can. --Richard Stallman
scottmaccal
 
Posts: 20
Joined: Fri Mar 28, 2008 2:12 am

Postby Lutz » Wed May 20, 2009 4:57 pm

Cormullion was showing you how to change the newLISP command line behavior, but perhaps this explains what you really want to do:

http://www.newlisp.org/newlisp_manual.html#read-line

Code: Select all
(define (main)
  (print "What can I assist you with? ")
  (set 'answer (read-line)))
)
Lutz
 
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Postby scottmaccal » Wed May 20, 2009 5:48 pm

Lutz wrote:Cormullion was showing you how to change the newLISP command line behavior, but perhaps this explains what you really want to do:

http://www.newlisp.org/newlisp_manual.html#read-line

Code: Select all
(define (main)
  (print "What can I assist you with? ")
  (set 'answer (read-line)))
)


Hi Lutz,

in a nutshell I'd like the user to be able to run an already defined and loaded function from within the newLISP interpreter without the user needing to type the () every time.

The program I am working on can be downloaded by: svn checkout http://faridayix.googlecode.com/svn/trunk/ faridayix-read-only A Mac is recommend if you have time/desire.

I am sure I breaking rules and probably doing bad design. But it is fun :-)
Whether gods exist or not, there is no way to get absolute certainty about ethics. Without absolute certainty, what do we do? We do the best we can. --Richard Stallman
scottmaccal
 
Posts: 20
Joined: Fri Mar 28, 2008 2:12 am


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 1 guest

cron