453 points · by jordigh · 10y ago · 183 comments
[0] - https://github.com/prakhar1989/type-inference
[1] - http://www.scheme.com/tspl4/examples.html#./examples:h10
I did SICP nearly 19 years ago as a freshman, in 1997. And then a few months ago, I ported the metacircular-evaluator -- the "crown" of the course -- to femtolisp (the Lisp implementation underlying Julia).
My thoughts were:
1) It sure is awkward to represent struct fields 1 2 3 as (cdr struct), (cadr struct), (caddr), ... Yes this is nice to show that car and cdr are all you need as axiomatic primitives, but for practical purposes it's annoying. You end up with lots of little functions with long names.
2) Scheme code is very imperative! Even the metacircular evaluator uses set-cdr! and so forth. I don't like imperative code with the Lisp syntax.
3) It is awkward to represent environments with assoc lists. I feel that having a language which is really bootstrapped requires some kind of hash table/dictionary. Because you need that to implement scopes with O(1) access rather than O(n). I believe there are experimental lisps that try to fix this.
4) Macros also seem to have a needlessly different syntax than regular functions. There are Lisps with f-exprs rather than s-exprs that try to fix this: https://en.wikipedia.org/wiki/Fexpr
I was surprised by #3 and #4 -- it some sense Scheme is less "meta" and foundational than it could be. #2 is also a fundamental issue... at least if you want to call it the "foundation" of computing and build Lisp machines; I think this is evidence that this idea is a fundamentally flawed. #1 just makes it pale into languages like Python or even JavaScript.
Every Scheme implementation I know of supports record types aka SRFI-9[0]. No one actually makes new data types from cons cells.
>2) Scheme code is very imperative!
Scheme supports many programming paradigms. Imperative programming is one. Functional programming, object-oriented programming, and relational programming are others. Not all Scheme code is imperative.
>3) It is awkward to represent environments with assoc lists.
Every Scheme implementation I know of has traditional mutable hash tables. Sometimes you want a hash table, sometimes you want an alist. It depends.
>4) Macros also seem to have a needlessly different syntax than regular functions.
I don't really understand this point. Are you talking about syntax-rules? If so, then I must disagree. syntax-rules is a very elegant language for defining hygienic macros.
SICP does not teach you everything that Scheme has to offer, and the Scheme implementations of the 1980s are a lot different than the Scheme implementations of 2016.
The Right Way to do this is with a D-List, or Detached List, analogous to an A-List or a P-List. An A-List, if you recall, is a list of key-value conses. A P-List is a list of alternating key-value pairs. A D-list is a cons of a list of keys and a list of values, i.e.:
((key1 key2 ...) val1 val2 ...)
D-lists are superior to A-Lists and P-Lists because:
1. The key list structure can be re-used
2. D-ASSOC only requires one traversal down the key list, after which the index of the key can be cached. This is usually the first step in writing a "fast" interpreter, but if you use A-Lists or P-Lists then you have to change data structures. If you use a D-List you already have the optimized structure in the CDR of the D-List pair.
3. Going from optimized interpreter to full compiler is a simple matter of replacing the linked list of values with a vector of values.
It's a shame that D-Lists are very rarely taught.
Hashing lexicals will not necessarily speed up an interpreter. It depends on what kind of code and how you do it. A lot of code has only a few lexicals at any binding level. If you construct a new hash table on each entry into a binding construct which has only a handful of variables, that could end up performing worse than the original assoc lists. You still have to cascade through multiple hash tables under that approach to resolve nesting. One hash table for an entire lexical scope leaves you with problems like how to resolve shadowing, and how to capture closures at different sub-nestings of that scope that have different lifetimes from containing scopes.
#2 - preach it.
#3 - The "big" schemes provide hash tables for you.
#4 - Well... fexprs used to be standard in lisp, but implementers didn't enjoy figuring out what a symbol meant at compile time.
I dunno, I really enjoy coding in scheme. Especially syntax-rules. I know syntax-case is the bees knees, but syntax-rules is pretty easy for me to model quickly.
It's interesting looking back on the history of Scheme. Probably because of the order of presentation of SICP, along with hearsay, people seem to get an impression of Scheme being all about functional programming (and if it's because functions are values you can pass around... well even Algol and Pascal could do that). It's true the original paper was called "Scheme: an interpreter for the extended lambda calculus" [1], but the big idea was that if variables were bound lexically, and if the environment structures used to close the variables were mutable, then you would have something like the actor model -- functions could have state and respond to messages. As they admit in the abstract, the purpose was to demonstrate the core interpreter for implementations of contemporary AI systems. The chapter on register machines in SICP is just an elaboration of their methods in this paper.
[1] http://repository.readscheme.org/ftp/papers/ai-lab-pubs/AIM-...
Something about porting a metacircular evaluator seems odd to me. Not that it's a bad exercise -- it's a good one. But rather, that it's no longer a _metacircular_ evaluator. The progression of the book is 1) abstracting processes and names with procedures 2) abstracting data representation 3) abstracting interface as a module, along with the theory and practice of mutation 4) abstracting semantics with interpreters (programs which take programs as data). The proof that 4 is a thing is by implementing an interpreter for the language in the language and then extending the interpreter in various ways. Even procedure calls are implemented by calling a procedure in the host language. (All I'm saying is that you exercised the metalinguistic abstraction by writing a scheme interpreter in femtolisp. Metacircularity in itself is not much more than an interesting phenomenon to demonstrate.)
(P.S. The language in SICP is not the Scheme which was later standardized, say R5RS + SRFIs. Mutation of lexical closures didn't change. You can't really (cleanly) get away from that until you invent something like a monad to model state.)
4: As I understand it, there are many macro systems available for Scheme. It's one of the languages in which "hygienic" macros has been explored, etc. So if you don't like the femtolisp bundled version, there might be another out there more to your taste.
Also, some people just really hate the parentheses (not me).
Also, some people really hate the Beatles (not me). More so in the '60s as contemporary artists, less so now when they're more likely to be referred to in a historical context. But still. The White Album had no shortage of devastating reviews when it came out.
I'd imagine Scheme as a teaching language would be less controversial in schools where the CS students are more likely to already know some programming when they start, and/or don't have as much of a trade school mentality.
You're lucky it isn't Fortran and a homegrown (crappy) macro language.... You can't fairly judge Scheme or C from a legacy codebase unless you judge every other language that way too.
Why would you need anything else for debugging?!?
I tried looking the course materials online but the Indiana University website gave me a 404 error page when I tried to access the course from Dybvig's website.
Thanks.
Good on Cisco for open sourcing it.
I'm interested to hear what regular scheme programmers feel about this news.
On the other hand, there's an intellectual idea that for many companies, existing software should perhaps be seen as a liability in double entry accounting due to it's need for ongoing maintenance, upgrades, potential for catastrophic failure, and the cost associated with alterations for new business processes.
Companies offload some of those costs by open sourcing and allowing developers to happily "give back" to their bottom line.
The part where Cisco open sourced it is a bit unusual, but it's not uncommon for people to close source and sell systems they create during college or grad school and continue to use them in research.
Also, does Gambit not support native threads? That's surprising considering Marc Feeley did quite a bit of research on multiprocessing in Scheme, and he wrote the SRFI for threads.
The racket/place library provides support for performance improvement through parallelism with the place form. The place form creates a place, which is effectively a new Racket instance that can run in parallel to other places, including the initial place. The full power of the Racket language is available at each place, but places can communicate only through message passing—using the place-channel-put and place-channel-get functions on a limited set of values—which helps ensure the safety and independence of parallel computations.
Compare to current Guile, where the documentation says sharing a hash table without using a mutex will not corrupt memory, but probably won't give you the results you desire.
SP-SW-LMIX0CH0 SP BASE Chez Scheme Dev Env for Wind, Per Unit $65.00
SP-SW-LMIX0CHL SP BASE Chez Scheme Dev Env for Linux, Per 10 $325.00
SP-SW-LMIX0CHW SP BASE Chez Scheme Dev Env for Wwind, Per 10 $325.00
SP-SW-LMIX0CH1 SP BASE Chez Scheme Dev Env for Apple Mac,Per 10 $325.00
SP-SW-LMIX0CHA SP BASE Chez Scheme Developm $65.00
SP-SW-LMX01CHL SP BASE Chez Scheme Developm $65.00 Chez Scheme Version 6
Software License Fee Schedule
V60901f
Supported machine types:
Intel 80x86 Linux 2.x
Intel 80x86 Windows 95/98/ME/NT/2000
Silicon Graphics IRIX 6.x
Sun Sparc Solaris 2.x
Classification License fee (USD)
-----------------------------------------------------------------
Single Machines
first machine per machine type $4000
each additional machine 3000
-----------------------------------------------------------------
Site
first machine type 9000
two machine types 14000
three or more machine types 19000
-----------------------------------------------------------------
Academic Site (for qualified academic institutions)
first machine type 4500
two machine types 7000
three or more machine types 9500
-----------------------------------------------------------------
Corporate
each machine type 24500the Apache 2.0 license includes not just copyright but patent licensing, so the software will contain no hidden patent restrictions for patents owned by the creators and contributors.
In my experience both terms are ambiguous. Many people seem to believe that "open source" simply means the source is available for examination. For example:
If you want to make an unambiguous statement, use "OSI approved license".
Other than Solidworks (which has everything from industrial machining stock cold-rolled steel and the finite-element analysis of your components all the way to computational fluid dynamics of anything your engineering heart could desire) I've never seen a company cover such an industry so thoroughly, so well[1].)
[1] Maybeeee Adobe has equal coverage re: for vector work with Illustrator/image manipulation with PS/page layout and typesetting with PageMaker/Indesign and doing post on Video with After Effects and such. And I don't think anyone would disagree, the degree of complexity for this genre of software is on a different tier.
edit: Haha. Confused Cadence Design Systems with Cadence Research Systems. Thanks for correcting me. Mea culpa. Keeping this up just for continuity sake. Viva la Scheme though! Have an upvote, @beering ;)
I'm not usually given to short, low-content comments here on HN, but:
wow!
Instead I just switched to guile (scheme implementation) trunk and got a 3x speedup. Did some optimizing work and it ended up at 4x, which is good enough.
Good.
I had trouble building it on Linux if I tried to set --installprefix= to a non-standard location, it built fine using the defaults. Nice!
On OS X, I have a clang version of gcc installed and perhaps because of that my build broke.
I installed gcc-5 using brew, set "alias gcc=gcc-5", and then ./configure ; sudo make install worked fine.
Maybe someone have managed to build the Windows version?