Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent terminal output in LISP

Tags:

output

lisp

I want to run a function but not have it output the result in the terminal. For example, (set 'A 'B) normally returns B in the console like the following:

 >>> (set 'A 'B)
 B
 >>> A
 B

I don't want it to return anything; I still want the function to do what it's supposed to, just silently:

 >>> (set 'A 'B)
 >>> A
 B
like image 724
pauliwago Avatar asked Jan 28 '26 19:01

pauliwago


2 Answers

It's not perfect, but you can use (values) at the end of your expression to suppress output. You get a blank line instead.

Common Lisp:

(progn (set 'A 'B) (values))

I'm not sure of the equivalent in Scheme.

A lisp REPL always prints some return value. If you really didn't want output, you could run your code as a script in the terminal.

Example:

#!/path/to/interpreter
(set 'A 'B)
[rest of program]
like image 177
user1613254 Avatar answered Jan 31 '26 01:01

user1613254


Since the value printed is actually a return value of your function, and the return value of a function is the value of last expression evaluated, you can simply add an "empty" (returning e.g. "") instruction at the end of/after your call.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!