write-you-a-scheme-v2 / scheme Goto Github PK
View Code? Open in Web Editor NEWWrite You a Scheme
Home Page: https://www.wespiser.com/writings/wyas/home.html
License: MIT License
Write You a Scheme
Home Page: https://www.wespiser.com/writings/wyas/home.html
License: MIT License
Repl> (begin (let (x 1 y 20 z 300)(+ x y z) ) )
Error Not a Function
Repl> (begin (define zzz 2)(let (x 1 y 20 z 300)(+ x y z) ) )
321
scheme/docs/01_introduction.md
Lines 43 to 44 in e09e25c
While working through the tutorial, I noticed that this would probably make more sense as a qualified import. I can definitely make the change but looking for guidance π
I believe https://wespiser.com/writings/wyas/home.html does not show the current version of the tutorial. For example https://wespiser.com/writings/wyas/00_overview.html does not include 39f2edf.
If the wespiser.com version of the text is not meant to be updated, then perhaps it would be a good idea to state this explicitly at the home page or in the overview, and recommend using the version from the repo?
From what I see, 5 years have passed but the last 3 chapters (Standard Library, IO, Conclusions) still have not been addressed (of these, IO being the most important probably). Should the project be considered abandoned, then?
The interactive repl, seen when running./run
, is very slow and sometimes does not register key presses. Using Haskeline 0.7.2.2
The Repl doesn't remember definitions:
Repl> (define myid (lambda (x) x))
myid
Repl> (myid 1)
Error Unbound Variable: myid
This works:
Repl> (begin (define myid (lambda (x) x)) (myid 1))
1
@sdiehl, having problems getting the parser to work creating LispVal values of strings
gce-work:scheme$ stack build && stack exec scheme
Repl> '(a)
List [Atom "a"]
Repl> '("a")
Parser "<stdin>" (line 1, column 4):
unexpected "a"
expecting end of "\"" or literal string
Repl> '(\"a\")
Parser "<stdin>" (line 1, column 4):
unexpected '\\'
expecting end of "("
It looks like the Parsec standard lisp parser is taking a different approach: https://hackage.haskell.org/package/lispparser-0.3.1/docs/src/Text-ParserCombinators-Parsec-Lisp.html
any insight on parsing in double quoted strings from the repl into LispVal?
Once you fix #23, you will find that the following happens:
(begin
(define y 42)
(define foo (lambda (x) x))
(let (y 12) (foo y)))
This evaluates to 42
instead of the expected 12
.
There are two causes:
applyLambda
takes args and evaluates them in the environment that was in scope when the closure was created (instead of assuming that the arguments passed in are already in evaluated form).eval
incorrectly passes xs
(ie, the unevaluated arguments) to the function definition instead of xVal
(the evaluated arguments).In https://github.com/write-you-a-scheme-v2/scheme/blob/master/docs/00_overview.md :
(car '(1 2 3))
should return 1
instead of (1)
.(cadr '(1 2 3))
should return 2
instead of (2 3)
or cdr
should be used instead of cadr
.from the project dir, run
./run
and enter (+ 1 2)
, there is a parser error.
The desired output is "List [Atom \"+\", Number 1, Number 2]"
./src/Parse.hs
should be updated...
This should be a good chance to write the docs on Parsec and parsing...
issue with new parser, parse3.hs
[1 of 1] Compiling Main ( Parse3.hs, Parse3.o )
Parse3.hs:18:9:
Couldn't match type β[Char]β with βT.Textβ
Expected type: Lang.GenLanguageDef T.Text () Identity
Actual type: Lang.LanguageDef ()
In the expression: Lang.emptyDef
In the expression:
Lang.emptyDef
{Tok.commentStart = "{-", Tok.commentEnd = "-}",
Tok.identStart = letter <|> oneOf "+-/*",
Tok.identLetter = alphaNum <|> oneOf "_'",
Tok.reservedOpNames = ["'", "\""],
Tok.reservedNames = ["true", "false", "let", ....]}
Consider the following example:
(begin
(define foo (lambda (x) y))
(let (y 42) (foo 0))
This evaluates to 42
rather than the expected: Unbound Variable: y
I think the repository name of scheme
is not descriptive enough and would like to propose changing it to something like write-you-a-scheme-v2
(like the organization). I know I can change the directory to which the project is cloned, but it's more user-friendly if one does not have to do that. :)
Running
stack build --test
in the main directory yields the following output:
src/Parser.hs
Atom
Num Negative
Num Positive
String
Bool True
Bool False
Nil
S-Expr: homogenous list
S-Expr: homogenous list quoted
S-Expr: heterogenous list
S-Expr: heterogenous list quoted
S-Expr: prim call: neg nums
S-Expr: prim call: atoms
S-Expr: nested list
Finished in 0.0029 seconds
14 examples, 0 failures
src/Eval.hs
test/add.scm
test/if_alt.scm
test/let.scm
test/eval_boolean.scm
test/eval_boolean_ops.scm
test/eval_lambda.scm
test/test_quote.scm
test/test_car.scm
test/test_cdr.scm
test/test_cadadr.scm
test/test_gt.scm
test/test_scope1.scm
test/test_args.scm
test/define.scm
test/define_order.scm
Finished in 0.2299 seconds
15 examples, 0 failures
eval extra -- sandboxing
begin/define
eval args
test/define_lambda.scm
eval args
foldl evals to something
foldl call FAILED [1]
fold FAILED [2]
Failures:
test-hs/Spec.hs:134:
1) eval extra -- sandboxing foldl call
uncaught exception: LispException (Error Type Mismatch: numeric op Nil)
test-hs/Spec.hs:134:
2) eval extra -- sandboxing fold
uncaught exception: LispException (Error Not a Function: (quote (quote (+))))
Randomized with seed 1448178989
Finished in 0.0720 seconds
7 examples, 2 failures
Further, scheme -s test/eval_lambda.scm
yields:
scheme: Error Not a Function: 5
and the code fails to correctly evaluate recursive structures (!), e.g. a factorial program in scheme will not work.
Hi @adamwespiser , first of all thanks a lot for providing a nice upgrade for Write Yourself a Scheme! As a beginner, it helped me grok Haskell and create projects out of it π
I'm just wondering if there would be any .pdf version of this. It may be helpful for someone like me who is not always connected to the internet / prefers reading on a paper print-out.
Thank you so much!
In the introduction the Evaluation Monad section mentions a guide about using monad transformers but its link - https://www.wespiser.com/writings/sources/Transformers.pdf - is broken. I couldn't find that file anywhere on your website, is it still available online?
Is the tutorial incomplete or the TOC is wrong: https://www.wespiser.com/writings/wyas/00_overview.html
I mean the Roadmap part is missing the links to the IO chapter etc...
Once #23 is fixed, you'll find that the following will not work:
(begin
(define (even x) (if (== x 0) #t (odd (- x 1)))
(define (odd x) (if (== x 0) #f (even (- x 1)))
(even 9))
Returns Unbound variable: odd
rather than the expected #f
Update: Actually once #23 and #25 are fixed, you'll find that even singly-recursive functions (such as foldl
from the stdlib) will not work. Just trying to get factorial working is worth thinking about.
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.