Skip to content

Instantly share code, notes, and snippets.

maybe:python-sibilant siege$ cat tacos.lspy
(defun make_tacos (X)
(cons 'tacos X))
(define tacos 'awesome)
maybe:python-sibilant siege$ python3
Python 3.5.3 (default, Apr 23 2017, 18:09:27)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
@obriencj
obriencj / output of sample.lspy
Created July 20, 2017 03:53
sibilant macros and quasiquote
maybe:python-sibilant siege$ sibilant sample.lspy
True is True
False is False
None is False
nil is False
True is True
100 is True
False is False
-100 is True
(1 will you 8 flake tacos_1 tacos_2 tacos_3 tacos_4 tacos_5 tacos_2 tacos_3 tacos_4 tacos_5)
@obriencj
obriencj / output
Last active July 21, 2017 19:53
example of sibilant line number table backtraces
maybe:python-sibilant siege$ python3 sample1.py
Traceback (most recent call last):
File "sample1.py", line 18, in <module>
call_a(100)
File "sample1.py", line 7, in call_a
call_1(call_b, value)
File "sample2.lspy", line 3, in call_1
(into arg))
File "sample1.py", line 11, in call_b
call_2(call_c, value)
@obriencj
obriencj / output of sample_defclass
Last active July 29, 2017 17:09
sibilant defclass sample
maybe:python-sibilant siege$ sibilant sample_defclass.lspy
Tom says: Hey there, Sally
Sally says: What's up, Tom
Tom says: Good-bye!
Sally says: Good-bye!
@obriencj
obriencj / specials.lspy
Created August 4, 2017 19:34
sibilant run and compile time special definition example
(defmacro pseudop (method . args)
(let ((as-name (symbol (+ "emit_" (str method))))
(method (symbol (+ "__compiler__.pseudop_" (str method)))))
(if args
`(defmacro ,as-name ,args
(cons ',method ,@args nil))
`(defmacro ,as-name ()
@obriencj
obriencj / gist:ed947df0d8b843ff0e7f6018ae5d79de
Created August 17, 2017 04:15
sibilant with set-macro-character
sibilant > $100
NameError: name '$100' is not defined
sibilant > (set-macro-character "$" (lambda (stream c) `(dollars ,(read stream))) False)
sibilant > $100
NameError: name 'dollars' is not defined
sibilant > '$100
(dollars 100)
sibilant > (defun dollars (amt) (print "YOU FOUND" amt "DOLLARS!!"))
@obriencj
obriencj / bindings.py
Last active September 14, 2017 18:09
local bindings from a map
#! /usr/bin/env python3
# This is a Proof-Of-Concept, and only works in Python3.
# A Python2 port is almost certainly possible, haven't even tried.
from inspect import currentframe
from dis import get_instructions
@obriencj
obriencj / example
Created September 17, 2017 18:57
mapbind works just fine in sibilant
maybe:python-sibilant siege$ sibilant
sibilant > (defimport mapbind)
sibilant > (define data (dict foo: 100 bar: 200 baz: 300 tacos: 'yum))
sibilant > data
{'tacos': <symbol 'yum'>, 'foo': 100, 'bar': 200, 'baz': 300}
sibilant > (define-values (foo bar baz) (mapbind.mapbind data))
sibilant > foo
100
sibilant > bar
200
@obriencj
obriencj / output
Created October 25, 2017 14:59
timing different fibonacci functions in the sibilant compiler
certainly:sample-project siege$ sibsampl timeit --fib 2000 --number 1000
calculating fibonacci of 2000
answer is 4224696333392304878706725602341482782579852840250681098010280137314308584370130707224123599639141511088446087538909603607640194711643596029271983312598737326253555802606991585915229492453904998722256795316982874482472992263901833716778060607011615497886719879858311468870876264597369086722884023654422295243347964480139515349562972087652656069529806499841977448720155612802665404554171717881930324025204312082516817125
fibonacci memoized -> maximum recursion depth exceeded
fibonacci via loop over 1000 loops -> 0.9649
fibonacci with TCO over 1000 loops -> 3.3678
fibonacci with TCR over 1000 loops -> 0.6501
certainly:sample-project siege$ sibsampl timeit --fib 300 --number 1000
calculating fibonacci of 300
answer is 222232244629420445529739893461909967206666939096499764990979600
class values(object):
def __init__(self, *args, **kwds):
self.__args = args
self.__iter__ = args.__iter__
self.__kwds = kwds
self.keys = kwds.keys