calysto / calysto_scheme Goto Github PK
View Code? Open in Web Editor NEWA Scheme kernel for Jupyter that can use Python libraries
License: BSD 3-Clause "New" or "Revised" License
A Scheme kernel for Jupyter that can use Python libraries
License: BSD 3-Clause "New" or "Revised" License
I threw together a quick Dockerfile that spins up a Jupyter notebook with Calysto Scheme.
https://github.com/joearasin/docker-jupyter-scheme
Not sure if you've used Docker at all, but it means that, with Docker setup, one line in the shell will spin up a notebook running Calysto scheme. It's useful in the context of "it'd be nice to have a notebook to work through SICP with".
docker run -d -p 8888:8888 -v
pwd:/notebooks joearasin/jupyter-scheme
Anyway, I was wondering if you had any interest in making it "official".
Need a start so we know when to clean out table.
Input: (/ 1.0 2.0)
Output:
Traceback (most recent call last):
File "In [45]", line 1, col 1, in '/'
UnhandledException: 'module' object has no attribute 'div'
While running the Calysto Scheme Language notebook (from master), I encountered this error :
(symbol "apple")
Traceback (most recent call last):
File "In [177]", line 1, col 2
RunTimeError: unbound variable 'symbol'
I ll try to investigate as far as I can, but do people who know Calysto Scheme have any hint ?
[TerminalIPythonApp] WARNING | Subcommand `ipython console` is deprecated and will be removed in future versions.
[TerminalIPythonApp] WARNING | You likely want to use `jupyter console` in the future
Traceback (most recent call last):
File "C:\Program Files\Anaconda3\lib\site-packages\jupyter_console\ptshell.py", line 323, in init_kernel_info
reply = self.client.get_shell_msg(timeout=1)
File "C:\Users\User\AppData\Roaming\Python\Python36\site-packages\jupyter_client\client.py", line 77, in get_shell_msg
return self.shell_channel.get_msg(*args, **kwargs)
File "C:\Users\User\AppData\Roaming\Python\Python36\site-packages\jupyter_client\blocking\channels.py", line 57, in get_msg
raise Empty
queue.Empty
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Anaconda3\Scripts\ipython-script.py", line 10, in <module>
sys.exit(start_ipython())
File "C:\Users\User\AppData\Roaming\Python\Python36\site-packages\IPython\__init__.py", line 125, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\traitlets\config\application.py", line 657, in launch_instance
app.initialize(argv)
File "<decorator-gen-113>", line 2, in initialize
File "C:\Program Files\Anaconda3\lib\site-packages\traitlets\config\application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "C:\Users\User\AppData\Roaming\Python\Python36\site-packages\IPython\terminal\ipapp.py", line 308, in initialize
super(TerminalIPythonApp, self).initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "C:\Program Files\Anaconda3\lib\site-packages\traitlets\config\application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "C:\Users\User\AppData\Roaming\Python\Python36\site-packages\IPython\core\application.py", line 450, in initialize
self.parse_command_line(argv)
File "C:\Users\User\AppData\Roaming\Python\Python36\site-packages\IPython\terminal\ipapp.py", line 303, in parse_command_line
return super(TerminalIPythonApp, self).parse_command_line(argv)
File "<decorator-gen-4>", line 2, in parse_command_line
File "C:\Program Files\Anaconda3\lib\site-packages\traitlets\config\application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\traitlets\config\application.py", line 514, in parse_command_line
return self.initialize_subcommand(subc, subargv)
File "C:\Users\User\AppData\Roaming\Python\Python36\site-packages\IPython\core\application.py", line 243, in initialize_subcommand
return super(BaseIPythonApplication, self).initialize_subcommand(subc, argv)
File "<decorator-gen-3>", line 2, in initialize_subcommand
File "C:\Program Files\Anaconda3\lib\site-packages\traitlets\config\application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\traitlets\config\application.py", line 452, in initialize_subcommand
self.subapp.initialize(argv)
File "<decorator-gen-117>", line 2, in initialize
File "C:\Program Files\Anaconda3\lib\site-packages\traitlets\config\application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\jupyter_console\app.py", line 141, in initialize
self.init_shell()
File "C:\Program Files\Anaconda3\lib\site-packages\jupyter_console\app.py", line 114, in init_shell
client=self.kernel_client,
File "C:\Program Files\Anaconda3\lib\site-packages\traitlets\config\configurable.py", line 412, in instance
inst = cls(*args, **kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\jupyter_console\ptshell.py", line 272, in __init__
self.init_kernel_info()
File "C:\Program Files\Anaconda3\lib\site-packages\jupyter_console\ptshell.py", line 326, in init_kernel_info
raise RuntimeError("Kernel didn't respond to kernel_info_request")
RuntimeError: Kernel didn't respond to kernel_info_request
```
That would take care of number/char issues.
(cd "~/path")
(define tolerance 0.0000001)
(define (fixed-point f first-guess)
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance))
(define (try guess)
(let ((next (f guess)))
(newline)
(display next)
(if (close-enough? next guess)
next
(try next))))
(try first-guess))
I use the calysto_scheme kernel in my jupyter. The code was running ok in MIT-scheme but in scheme kernel there was something wrong. So I think there must have a bug in it.
thank you.
Probably shouldn't be able to do this:
In [2]: (define-syntax 5.4
: [(time ?exp) (let ((start (current-time)))
: ?exp
: (- (current-time) start))])
https://github.com/Calysto/calysto_scheme/search?q=caaar
got a hard time reading caadar caaddr caadr caar cadaar cadadr cadar caddar cadddr in the tutorial
can anyone explain this?
Image jupyter/notebook
doesn't exist anymore, so I took the liberty to create another image from nbgallery/jupyter-alpine
(https://github.com/nbgallery/jupyter-alpine).
The alpine based image is supposed to be minimal. The final image is ~407MB.
The dockerfile is as follows:
FROM nbgallery/jupyter-alpine
RUN mkdir /app
WORKDIR /app
RUN pip3 install --upgrade pip
RUN pip3 install --upgrade jupyter
RUN pip3 install --upgrade notebook
RUN pip3 install --upgrade calysto-scheme
RUN python3 -m calysto_scheme install
CMD jupyter notebook --allow-root --ip=0.0.0.0 --port=80
It can be downloaded from my Docker hub as gchamon/calysto-scheme-alpine:latest
and run as docker run -it -p 8888:80 -v $(pwd):/app gchamon/calysto-scheme-alpine
Feel free to use the Dockerfile at will!
Thanks for the kernel! It is helping me a lot with SICP
Consider the following, which came up while writing a metacircular evaluator in calysto:
(case 'begin
((begin) 'foo-begin)
((define) 'foo-define)
(else 'foo-else))
In Gambit Scheme, this produces
Gambit v4.9.4-132-gb9304a3b
> (case 'begin
((begin) 'foo-begin)
((define) 'foo-define)
(else 'foo-else))
foo-begin
In calysto Scheme, this produces a parse error (I've run "test_all.ss" in the same REPL session to show that everything else seems OK):
└─(15:25:53 on master ✹ ✚ ✭)──> python scheme.py 2 ↵ ──(Tue,Dec27)─┘
Calysto Scheme, version 1.4.7
----------------------------
Use (exit) to exit
==> (case 'begin
((begin) 'foo-begin)
((define) 'foo-define)
(else 'foo-else))... ... ...
...
Traceback (most recent call last):
ParseError: bad concrete syntax: (begin)
==> (load "test_all.ss")
Testing group 'defines'...
Testing group 'range'...
Testing group 'sort'...
Testing group 'main'...
Testing group 'mu-lambda'...
Testing group 'define'...
Testing group 'call/cc'...
Testing group 'try'...
Testing group 'loop'...
Testing group 'macros'...
Testing group 'datatype'...
Testing group 'named-parameters'...
=================
Testing completed!
Time : 0.37 seconds
Total tests defined: 247
Total tests tested : 247
Right: 247
Wrong: 0
==>
For example:
(let () 3)
When I pip3 install --upgrade calysto-scheme
, the installation fails with:
File "/private/var/folders/xb/5q674_3x6kl7v8vczp17p6gr0000gn/T/pip-build-3b37q2b2/calysto-scheme/setup.py", line 49, in <module>
with open('README.md') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'README.md'
I downloaded calysto_scheme-0.8.2.tar.gz manually, and untarred the output:
tar -xvzf calysto_scheme-0.8.2.tar.gz
x calysto_scheme-0.8.2/
x calysto_scheme-0.8.2/setup.py
x calysto_scheme-0.8.2/calysto_scheme/
x calysto_scheme-0.8.2/calysto_scheme/scheme.py
x calysto_scheme-0.8.2/calysto_scheme/__init__.py
x calysto_scheme-0.8.2/calysto_scheme/kernel.py
x calysto_scheme-0.8.2/calysto_scheme/__main__.py
x calysto_scheme-0.8.2/PKG-INFO
So the file isn't making it into the build.
Checking out the git repo and doing python setup.py install
works fine.
Just use paren balanced? And make sure there isn't anything else.
I just tried pip installing calysto in my local virtualenv and ipython/jupyter 5 cannot find the kernel:
$ python --version
Python 2.7.10
$ pip freeze | grep -E 'jupyter|ipython|calysto|metakernel'
calysto-scheme==1.2.0
ipython==5.1.0
ipython-genutils==0.1.0
jupyter==1.0.0
jupyter-client==4.3.0
jupyter-console==5.0.0
jupyter-core==4.1.0
metakernel==0.14.0
$ ipython console --kernel calysto_scheme
[TerminalIPythonApp] WARNING | Subcommand `ipython console` is deprecated and will be removed in future versions.
[TerminalIPythonApp] WARNING | You likely want to use `jupyter console` in the future
Traceback (most recent call last):
File "/home/mark/.virtualenvs/web/bin/ipython", line 11, in <module>
sys.exit(start_ipython())
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/IPython/__init__.py", line 119, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/traitlets/config/application.py", line 595, in launch_instance
app.initialize(argv)
File "<decorator-gen-109>", line 2, in initialize
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/traitlets/config/application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/IPython/terminal/ipapp.py", line 300, in initialize
super(TerminalIPythonApp, self).initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/traitlets/config/application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/IPython/core/application.py", line 446, in initialize
self.parse_command_line(argv)
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/IPython/terminal/ipapp.py", line 295, in parse_command_line
return super(TerminalIPythonApp, self).parse_command_line(argv)
File "<decorator-gen-4>", line 2, in parse_command_line
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/traitlets/config/application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/traitlets/config/application.py", line 488, in parse_command_line
return self.initialize_subcommand(subc, subargv)
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/IPython/core/application.py", line 236, in initialize_subcommand
return super(BaseIPythonApplication, self).initialize_subcommand(subc, argv)
File "<decorator-gen-3>", line 2, in initialize_subcommand
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/traitlets/config/application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/traitlets/config/application.py", line 426, in initialize_subcommand
self.subapp.initialize(argv)
File "<decorator-gen-113>", line 2, in initialize
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/traitlets/config/application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/jupyter_console/app.py", line 137, in initialize
self.init_shell()
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/jupyter_console/app.py", line 105, in init_shell
JupyterConsoleApp.initialize(self)
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/jupyter_client/consoleapp.py", line 334, in initialize
self.init_kernel_manager()
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/jupyter_client/consoleapp.py", line 288, in init_kernel_manager
self.kernel_manager.start_kernel(**kwargs)
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/jupyter_client/manager.py", line 230, in start_kernel
kernel_cmd = self.format_kernel_cmd(extra_arguments=extra_arguments)
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/jupyter_client/manager.py", line 170, in format_kernel_cmd
cmd = self.kernel_spec.argv + extra_arguments
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/jupyter_client/manager.py", line 82, in kernel_spec
self._kernel_spec = self.kernel_spec_manager.get_kernel_spec(self.kernel_name)
File "/home/mark/.virtualenvs/web/local/lib/python2.7/site-packages/jupyter_client/kernelspec.py", line 175, in get_kernel_spec
raise NoSuchKernel(kernel_name)
jupyter_client.kernelspec.NoSuchKernel: No such kernel named calysto_scheme
jupyter console --kernel calysto_scheme
gives similar results.
Apply's looks like this:
list->vector(args)
f(*args)
I think we can just put them in a vector to begin with.
In Python, you can create a new class like this:
A = type("A", (SUPERCLASS, ...), {ATTRIBUTE: ..., })
If we do it that way, and an ATTRIBUTE is a Scheme function, we have to manually pass in self.
remove special forms from (dir)
Windows 10 Pro
{micha} [122] --> python -V
Python 3.10.0
emacs:\org-new\org-mode
{micha} [123] --> pip install --upgrade calysto-scheme --user
emacs:\org-new\org-mode
{micha} [118] --> python -m calysto_scheme install --user
Traceback (most recent call last):
File "C:\Python310\lib\runpy.py", line 187, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "C:\Python310\lib\runpy.py", line 146, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "C:\Python310\lib\runpy.py", line 110, in _get_module_details
__import__(pkg_name)
File "C:\Users\micha\AppData\Roaming\Python\Python310\site-packages\calysto_scheme\__init__.py", line 2, in <module>
from .kernel import CalystoScheme
File "C:\Users\micha\AppData\Roaming\Python\Python310\site-packages\calysto_scheme\kernel.py", line 4, in <module>
from calysto_scheme import scheme
File "C:\Users\micha\AppData\Roaming\Python\Python310\site-packages\calysto_scheme\scheme.py", line 16, in <module>
from collections import Iterable
ImportError: cannot import name 'Iterable' from 'collections' (C:\Python310\lib\collections\__init__.py)
The kernel is actually installed, but it's broken for the reason shown. On my linux machine, which has Python 3.8, I get this message:
Deprecation warning: using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated
since Python 3.3 and in 3.9 it will stop working.
Excuse me... i want to use random
in calysto_scheme .But I find that I don't know how to use a python lib in it......can you give me some structions ?
The exp
and log
functions are undefined:
(exp 3)
Traceback (most recent call last):
File "In [21]", line 1, col 2
RunTimeError: unbound variable 'exp'
(log 10)
Traceback (most recent call last):
File "In [21]", line 1, col 2
RunTimeError: unbound variable 'log'
i'm trying to write a simple python code for arithmetic operation
x=int(c[1])/320 print(c) print(c[1],round(x,2))
c=['S1069L03.jpg', '178', '142', '102', '\n']
(c[1],round(x.2))=('178', 0.0)
### the result is false because 178/320=0.55
does anyone have an idea how i can resolve it
I've been using Calysto to learn Scheme using the exercises from SICP in a Jupyter notebook. While running one of my examples, I noticed that it was failing where before it had passed. I believe that this is because the first time I ran the code, the function good-enough?
was only defined in the local scope, while the second time I had just re-run all of the code in the notebook, causing it to be defined externally.
My code is located here: https://github.com/arlindohall/sicp/blob/master/Chapter1.ipynb
According to what I've learned so far, this should cause the local definition to be used, but Calysto used the global definition. I think this is the case, because the error I got was:
Traceback (most recent call last):
File "In [7]", line 16, col 1, in 'sqrt'
File "In [7]", line 14, col 3, in 'sqrt-iter'
File "In [5]", line 2, col 7, in 'good-enough?'
File "In [5]", line 14, col 11, in '-'
UnhandledException: unsupported operand type(s) for -: 'float' and 'NoneType'
and the global definition of good-enough?
has two arguments, while the local one only has one argument.
Steps to reproduce:
(define (sqrt x)
(define (square y)
(* y y))
(define (average a b)
(/ (+ a b) 2))
(define (good-enough? guess)
(< (abs (- (square guess) x)) 0.001))
(define (improve guess)
(average guess (/ x guess)))
(define (sqrt-iter guess)
(if (good-enough? guess)
guess
(sqrt-iter (improve guess))))
(sqrt-iter 1.0))
(sqrt 9)
(define (abs x)
(if (< x 0)
(- x)
x))
(define (square x) (* x x))
(define (good-enough? guess x)
(< (abs (- (square guess) x)) 0.001))
(define (sqrt x)
(define (square y)
(* y y))
(define (average a b)
(/ (+ a b) 2))
(define (good-enough? guess)
(< (abs (- (square guess) x)) 0.001))
(define (improve guess)
(average guess (/ x guess)))
(define (sqrt-iter guess)
(if (good-enough? guess)
guess
(sqrt-iter (improve guess))))
(sqrt-iter 1.0))
(sqrt 9)
Traceback (most recent call last):
File "In [5]", line 1, col 1, in 'sqrt'
File "In [4]", line 14, col 3, in 'sqrt-iter'
File "In [4]", line 11, col 9, in 'good-enough?'
File "In [3]", line 7, col 11, in '-'
UnhandledException: unsupported operand type(s) for -: 'float' and 'NoneType'
Behavior in GNU Scheme:
1 ]=> (define (sqrt x)
(define (square y)
(* y y))
(define (average a b)
(/ (+ a b) 2))
(define (good-enough? guess)
(< (abs (- (square guess) x)) 0.001))
(define (improve guess)
(average guess (/ x guess)))
(define (sqrt-iter guess)
(if (good-enough? guess)
guess
(sqrt-iter (improve guess))))
(sqrt-iter 1.0))
;Value: sqrt
1 ]=> (sqrt 9)
;Value: 3.00009155413138
1 ]=> (define (abs x)
(if (< x 0)
(- x)
x))
(define (square x) (* x x))
(define (good-enough? guess x)
(< (abs (- (square guess) x)) 0.001))
;Value: abs
1 ]=>
;Value: square
1 ]=> (define (sqrt x)
(define (square y)
(* y y))
(define (average a b)
(/ (+ a b) 2))
(define (good-enough? guess)
(< (abs (- (square guess) x)) 0.001))
(define (improve guess)
(average guess (/ x guess)))
(define (sqrt-iter guess)
(if (good-enough? guess)
guess
(sqrt-iter (improve guess))))
(sqrt-iter 1.0))
;Value: good-enough?
1 ]=> (sqrt 9)
;Value: sqrt
1 ]=>
;Value: 3.00009155413138
(exit) should actually exit
quit should be re-defined or removed
The classic SCIP handbook has this example:
(define tolerance 0.00001)
(define (fixed-point f first-guess)
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance))
(define (try guess)
(let ((next (f guess)))
(if (close-enough? guess next)
next
(try next))))
(try first-guess))
The always code returns first-guess
when running it in Calysto Scheme, while working correctly in other dialects of Scheme. When the code is modified by renaming try
to something else, it works correctly.
I would expect it to either allows me to re-define the symbol, or at least throw an error if this is not allowed.
Hi,
Is there a way to call (Python) host functions with named parameters like in this
import subprocess
process = subprocess.Popen(['echo', 'More output'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
Calysto is great and I would like to use it more for everyday scripting.
Thanks,
Ben
Hi, I noticed (after some troubleshooting) that dicts created by (dict ...)
and by (python-eval "...")
look exactly the same but behave differently:
(define a (python-eval "{'a' : 1}"))
a => {'a' : 1}
(define b (dict '(b : 2)))
b => {'b' : 2}
(get-item a 'a) => 1
(get-item b 'b) => error
(get-item a "a") => 1
(get-item b "b") => 2
While I know that that behaviour is to be expected, couldn't its representation be different to emphasize the incompatibility? e.g.
b => {"b" : 2}
or change the symbol-based one
a => {'a : 2}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.