Quantcast
Channel: Hacker News 100
Viewing all articles
Browse latest Browse all 5394

bodil/BODOL · GitHub

$
0
0

Comments:"bodil/BODOL · GitHub"

URL:https://github.com/bodil/BODOL


BODOL

This is my language experiment.

Preliminary goals which may or may not be possible to combine:

  • Pure functional language.
  • Homoiconic in the Lisp tradition.
  • Built on the traditional Lisp primitives.
  • Hindley-Milner flavoured type system.
  • Currying function calls.
  • Pattern matching.

This is a work in progress. Don't expect it to even run its own test suite.

Not Implemented Yet

The language, and the reference implementation (which, be warned, is just a dumb, slow interpreter), still misses these things:

  • Type system.
  • Macros.
  • Module system.
  • A decision on lazy vs strict evaluation.

Inspiration

Clojure is great, but sometimes I miss static typing. Haskell is great, but sometimes I miss Lisp's elegantly simple syntax. Shen is a splendid compromise, but I found myself wishing it came with Haskell's uncompromising purity and Standard ML's straightforward type system. BODOL is my attempt at crossbreeding the three, with Shen obviously the major influence.

A Taste of BODOL

Functional hello world:

(ƒfactorial0->1n->(*n(factorial(-n1))))(ƒfibonacci0->01->1n->(+(fibonacci(-n1))(fibonacci(-n2))))

More advanced pattern matching:

(ƒmapf()->()f(head.tail)->(cons(fhead)(mapftail)))(='(234)(map(λa->(+a1))'(123))))

Currying:

(ƒtripletabc->(listabc))(defineone-and(triplet1))(defineone-and-two-and(one-and2))(='(123)(one-and-two-and3))

Take a look at the theoretically comprehensivetest suite for examples of all the currently defined language features.

Test Drive

The BODOL prototype interpreter is written in Clojure, so you'll need to install Leiningen in order to run it. Optionally, you may also want to installrlwrap for a better line editing experience. Once that's done, check out the BODOL repo, cd over there and type:

$ ./repl
BODOL version 0.0.0
You are in a maze of twisty little passages, all alike.
→→

What's with those non-ASCII characters?

If you're discouraged by the curious absence of λ and ƒ on your keyboard, you can substitute Clojure's fn and defn or Common Lisp's lambda and defun respectively.

Emacs bindings

If you're using Emacs, I find it helps to bind ƒ and λ to M-f and M-l (Alt+F and Alt+L) respectively.

;; Keybindings for λ and ƒ(global-set-key(kbd"M-l")(lambda()(interactive)(insert"\u03bb")));lambda(global-set-key(kbd"M-f")(lambda()(interactive)(insert"\u0192")));function;; Launch the BODOL REPL in an inferior-lisp buffer(defunbodol-repl()(interactive)(run-lisp"<path to your BODOL repo>/repl"))

Vim bindings

Add this snippet to your .vimrc to enable the same keybindings for vim.

" Keybindings for λ and ƒ:inoremap<A-l><C-v>u3bb<Space>:inoremap<A-f><C-v>u192<Space>

Mac OS X keybindings

If you're using Mac OS X, you can enable these keybindings globally by adding the following snippet to~/Library/KeyBindings/DefaultKeyBinding.dict.

{
"~f" = ("insertText:", "\U0192"); /* alt + f ~> florin */
"~l" = ("insertText:", "\U03BB"); /* alt + l ~> lambda */
}

License

Copyright 2013 Bodil Stokke

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


Viewing all articles
Browse latest Browse all 5394

Trending Articles