How can I clear the console in sicstus prolog? [duplicate] - prolog

I'm using SICStus 4.2.0 and I was not able to find out how to clear the content of the console. Is it even possible?

write('\33\[2J').
This is in no way specific to SICStus. It is the ANSI escape code and works in any ISO conforming system.

While SWI-Prolog provides a tty_clear predicate in its tty library, Sicstus doesn't seem to have a built-in alternative for this. But there is a simple workaround (for unix/linux, may not be that simple on windows): You can start the sicstus shell via rlwrap, which is a readline-wrapper for arbitrary shell commands. Besides the obvious benefit of the command history, this also means you can now use other shell functionality in sicstus, like the left/right arrow keys, home/end keys, Ctrl-k for deleting everything after the cursor, and Ctrl-l to clear the screen.
rlwrap is available as a package for many linux distributions, for windows you would need to use cygwin - this article describes how to setup rlwrap with powershell (for use with sqlplus in this case) so I guess powershell is a requirement too.
In summary, once you have rlwrap installed, simply start sicstus as rlwrap sicstus and use Ctrl-l to clear the screen.

I have spent some time looking through the documentation and I could not find a way to programmatically clear the console screen (in case this is possible, I am happy to be proven wrong). Alternatively, you might want to use SPIDER, that is a SICStus Prolog IDE: http://sicstus.sics.se/spider/ In Spider, the ordinary TopLevel interface has the option of clearing the current content of the console. Hope this helps.

If you're using swipl, then add this line in your user init file:
cls:-write('\33\[2J').
That should do it.

Related

REPL with features of modern shell

I am creating a script (in Lisp, though this can apply to any language with a REPL) which users interface with using the language's REPL. But this does not include even basic interactive features like remembering history. I am wondering if it is possible to tell a terminal emulator to interpret commands using an arbitrary language, instead of the built-in language.
Thanks!
OK, follwoing the advice of user2864740, I looked at GNU Readline, which is the library the provides much of the functionality that I'm looking for. I'm going to switch to Guile Scheme instead of Common Lisp since Guile supports Readline out of the box. However, it looks like it can work in Common Lisp as well: http://www.cliki.net/sb-readline
Yet another approach might be to start the editor emacs, run
M-x shell
and in this shell run your Lisp REPL. You get a lot of feature for free, like command history.

SWI-Prolog Editor for OS X

I was searching for a SWI-Prolog editor for Mac OS X but i could not find one, so is there one or do I have to use another editor to build Prolog files?
Thanks
I do not use mac OS-X myself, but there are two very good SWI-Prolog editors that are cross-platform (thus also work on OS-X):
PDT works with the Eclipse IDE. It has good syntax coloring, an in-IDE Prolog console, a dynamically generated visualization of the call graph, to name only a few of the many features it has. See http://sewiki.iai.uni-bonn.de/research/pdt/docs/v2.1/start I believe refactoring of Prolog code is not there yet, but the developers plan to add that cool feature in the future as well.
PCE Emacs, an Emacs implementation by Jan Wielemaker that uses SWI-Prolog's graphical library XPCE. The UI elements look very Windows '95-ish, but don't be fooled by mere appearances here. PCE Emacs is completely tuned to SWI-Prolog and is probably the most versatile editor for SWI-Prolog out there. You can simply run it from within the SWI-Prolog console by typing emacs.
Hope this helps!
Assuming that you're considering not only IDEs but also text editors, the Logtalk distribution includes support for a large number of text editors that is also usable for editing Prolog source code. See https://github.com/LogtalkDotOrg/logtalk3/tree/master/coding for a list of all supported text editors.
I use OS X and work in Emacs with prolog-mode.
This version has all the features one would expect, including syntax highlighting, auto indent, and full interaction with an inferior Prolog process. The mode supports in principle any Prolog system, though it is primarily maintained with SWI Prolog in mind.
It lacks many of the features of PCE Emacs, but has all of the features of GNU Emacs, and I'm pretty happy with it.

Sicstus Prolog: display current bindings during debugging

I'm very new to Prolog and have been using Sicstus to help debug my code. Is there a way to view all the bindings while you are stepping through a query using trace/0? Or is there some other way to print out during the steps?
This is done automatically if you use the SPIDER IDE. You can also show the bindings when running SICStus from within the Emacs mode and, finally, the debugger can print the bindings using the 'v' debugger command.
Not all variables are available since some variables may disappear due to compiler optimization. If this is a problem you can use consult/1 to run the code interpreted. This is slower but sometimes gives somewhat more details in the debugger.
If using Sicstus with Emacs then C-c C-g will open a buffer that will display prolog bindings as you step through with trace

something similar to Emacs shell?

I'm looking for something similar to Emacs shell.
I want to be able to select text easily in my terminal, be able to manipulate the output.
Unfortunately, emacs is not always an option. I can't figure out how to make a few things (e.g autocompletion) work the way it does in gnome-terminal and it is a bit of a pain on remote system.
I would rather not spend the time fixing/configuring Emacs unless there is a cool piece of software out there doing something similar to gnome-terminal + let's me manipulate the output without touching the bloody mouse.
Thanks for your help,
-hbt
I'm not sure I completely understand the question, but if you're looking for terminal emulation inside of Emacs, there are at least four options bundled with Emacs 22+ that offer varying levels of xterm-like capability:
term
ansi-term
shell
eshell
eshell, IMO, is the most departed from the tradtional "xterm" experience, but also offers the most buffer-like experience, and it is cross-platform, which is a huge win.
I think shell might be the sweet spot for you if you're looking for term-like behavior, while retaining the editing capabilities.
Finally, term and ansi-term are very term-like, and will behave almost exactly like a xterm/konsole/gnome-shell session.
One other note: if you want scrollback access, copying, pasting, etc. and you don't have Emacs available, I highly recommend learning and using GNU Screen.
You should try the Emacs terminal emulator term(or its colored version ansi-term). There are other terminal emulators for Emacs around, but this is the most popular(and the only one bundled with the default installation).
Looks like you want to look into readline on bash (or if available on your favourite shell). A quick google gives a few links here (including a cheatsheet).
I was also looking for some kind of shell like emacs, with support to some feature like emacs buffers for example. That would be great.
I just found this one: Terminator
Have a look:
http://www.makeuseof.com/tag/5-applications-to-change-the-way-you-work-with-linux-terminal/

linux/bash tips for developers? [duplicate]

This question already has answers here:
Closed 13 years ago.
Possible Duplicates:
Favourite command line trick
useful linux commands for programmers?
What is your single most favorite command-line trick using Bash?
I have recently become accustomed to doing most of my development (in various languages) from the bash shell, using command-line tools and interfaces. I have discovered it is convenient to stay in the command line because you can do many things without leaving that interface, and it is fast.
What tools and tricks are you aware of that can make bash (perhaps in conjunction with an editor like vim or emacs) a more powerful development environment to work in?
Start with an X11 window manager that works well without needing a mouse.
Awesome
xmonad
After that:
screen
bash_completion
vim
cscope
ctags
remake
I rarely need to touch the mouse for anything.
You've probably done some or all of this, but for the record...
ctags/etags
plugins for vim and emacs
get to know the bash ! history substitution feature (but be careful! :-)
if using vi (over emacs) then get to know the :line mode
you might want to check out the id-utils package
if using bash on windows via cygwin, use rxvt instead of the default dos box
You also want to set up each tool in the programmer mode. Editors like vi and emacs can autoindent, show matching parens, etc. You need to read the help and turns these things on. Be sure that you run bash in the history mode that matches your editing reflexes. It defaults to emacs but for vi one does set -o vi.
First, I use intensively shortcuts. Then, I could obviously mention things like vim, grep, tail, head, find, sudo !!,... But one thing I really can't live without is Programmable Completion. Of course, this will depend on your habit, but here are some must have for me:
Ant Bash Completion
command line completion in GlassFish
Grails Bash Completion and/or Autocomplete Grails Script Names in bash/zsh
Maven Tab Auto Completion in Bash
Oh let's see... cut, sort, grep, find

Resources