This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; you'll need to clone green-threads and cl-async into ~/quicklisp/local-projects | |
(ql:quickload "green-threads") | |
(ql:quickload "cl-async") | |
(defun f-http-client (url &rest rest) | |
(let ((http-future (green-threads:make-future))) | |
(apply #'cl-async:http-client | |
url | |
#'(lambda (status headers body) | |
(green-threads:complete-future |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ql:quickload "green-threads") | |
(ql:quickload "cl-async") | |
(defun f-http-client (url &rest rest) | |
(let ((http-future (green-threads:make-future))) | |
(apply #'cl-async:http-client | |
url | |
#'(lambda (status headers body) | |
(green-threads:complete-future | |
http-future status headers body nil)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In Python it is common (though probably inadvisable) to | |
# use Exceptions for flow control in situations that are | |
# really not that exceptional. The Exception classes | |
# function as symbols for what is essentially symbolic | |
# programming using the exception handling machinery | |
# for the actual flow control. | |
class ValidationError(Exception): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ql:quickload "cl-async") | |
(ql:quickload "green-threads") | |
(cl-cont:defun/cc my-delay (time) | |
(cl-cont:let/cc continuation | |
(as:delay continuation :time time))) | |
(as:start-event-loop | |
(lambda () | |
(gt:with-green-thread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Is a dynamically typed language w/ optional type annotations and type-inferring compiler strictly better than a statically typed language with type inference? | |
0. Both languages have "strong" typing in the sense that values have definite types. | |
1. Any expression that would trigger an obvious type error (eg. calling string-concatenation function with 2 numeric constants) in compilation in the static lang, would trigger a similar warning in the dynamic language. The dynamic language would allow the program to actually compile and run and (presumably) fail at runtime, but would give you the option to fail compilation on these types of warnings (--fail-on-type-error). | |
2. Any expression that cannot be properly type inferred would fail compilation for the statically typed language but would succeed (with a lesser warning) for the dynamic language with the option to fail compilation for this type of warning, also (--fail-on-unknown-type). | |
3. For identical code, there is no reason that the dynamically typed langua |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% example: move([0,0],[X,Y],7,7). | |
% because this is not right: https://github.com/clojure/core.logic/wiki/Translations-from-prolog | |
move([X, Y], [A, B], Xmax, Ymax) :- | |
member([Dx,Dy],[[1,2],[2,1],[2,-1],[1,-2],[-1,-2],[-2,-1],[-2,1],[-1,2]]), | |
A is X + Dx, | |
B is Y + Dy, | |
between(0, Xmax, A), | |
between(0, Ymax, B). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:- use_module(library(clpfd)). | |
peano(N,z) :- N #= 0. | |
peano(N,s(PDec)) :- | |
N #> 0, | |
N - 1 #= NDec, | |
peano(NDec, PDec). | |
% ?- peano(4, Q). | |
% Q = s(s(s(s(z)))) ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Boo macro for delegating to subgenerators ala PEP 380 | |
macro yield_from: | |
yield [| | |
for _x in $(yield_from.Arguments[0]): yield _x | |
|] | |
def myrange(): | |
yield_from range(99) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def values_in(keys, dict_): | |
Nothing = object() | |
vals = (dict_.get(key, Nothing) for key in keys) | |
return [x for x in vals if x is not Nothing] |