Hi,
I would like to add an interactive shell/interpreter/REPL feature to a graphical (Erlang) application, like a pane containing a text control in which commands could be issued and their result be shown once processed; like the Erlang shell, except that the I/O (collect the user input, display the output) would be done by the user program.
For the interpreter logic I was hoping to find in the shell
module a function like process(chardata()) -> chardata()
, possibly with input/output bindings, or a state/PID to interact with, but could not find any. Is there a way of doing so with the standard modules? If not, how websites like Erlang - Replit or https://www.tryerlang.org/ do?
Thanks in advance for any information,
Best regards,
Olivier.
I’ve had this old mailing list thread bookmarked for a bit for my own project idea.
https://erlang.org/pipermail/erlang-questions/2008-September/038476.html
It shows a simple REPL implementation that you should be able to hack around with.
2 Likes
Hi Harley and Felix, thanks for the links. Fred Hebert’s article shows clearly how powerful, yet a bit complex, the shell infrastructure became. As I understand it, it would “suffice” to introduce a new process registered as user_drv
and able to interact with a group
-based server process in order to drive the evaluation according to a GUI. Perhaps that a restricted shell (to avoid silly mistakes) and some way of making a base module implicit (as if its functions were available as local ones) could be of use. Possibly something to try one day!
Thanks,
Olivier.
The shell
module does provide a restricted shell. The implicit base module for the shell internal commands (help()
) is shell_default. You may add your own short commands by providing a user_default
module.
2 Likes
Hi Vance, thanks for these information ; it looks as if at least most components were already available and waiting to be assembled! Defining one’s little “DSL” that way / providing a programmable text user-interface (like done by some programs exhibiting a Python-based one) could be quite convenient.