PeterBortas / mal-candidates

Languages I consider implementing MAL in

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature wish list for implementation candidates

  • Reading from stdin, printing to stdout and reading files
  • Accessing argv
  • Loading code from other files or better, a module system
  • Regex
  • An usable type system or dynamic typing
  • User-defined exceptions
  • Closures
  • Higher-order functions or at least function pointers (functors can work, but are yucky)
  • Apply
  • Extensible objects
  • Records/structs/objects
  • Numbers(!), arrays(!!), hash tables (can be faked with arrays)
  • Measuring time, alternatively shelling out
  • Linux support for the CI to work, alternatively Windows or OS X
  • FFI or dynamically loadable modules to use GNU Readline

Hacks and workarounds for missing features

Stdin reading

  • If you can read from files, try /dev/stdin (see supercollider/util.sc)
  • Consider writing some wrapper script that does this and somehow communicates with the language (like by using TCP sockets, OSC, a HTTP server with JSON as transport, …)
  • Anything goes really, see https://github.com/kanaka/mal/blob/master/plpgsql/io.sql

ARGV

  • If there’s no access to ARGV, but you can fetch environment variables, modify run so that it exports a QX_ARGV environment variable with all values joined by a separator (like NUL, bell, vertical tab, emoji, …)
  • Alternatively, have run write ARGV with all values joined by a separator to a file and read it from the program

Loading code from other files

  • Careful, just loading code might be useless if the load isn’t relative to the current file
  • If there’s no load-relative facility or a way to make one, consider concatenating all source files to one file to be executed by using the Makefile
  • Alternatively, if loading multiple files is supported, write a runner script that loads them in the right order
  • Note that you’ll still have to either figure out dependencies or declare them by putting comments pointing to the required files there, see https://github.com/kanaka/mal/blob/master/chuck/stepA_mal.ck

Regex

Type system

Exceptions

  • The guide suggests introducing an errno-like construct, but this is highly error-prone
  • An easier alternative is creating an error type and returning error objects, however you’ll still have to check for it after every call to EVAL or you’ll run into saving errors into variables…

Closures

Higher-order functions

Apply

Objects

Numbers

Arrays

  • Hopefully you’ll be able to use a list/vector type instead
  • Otherwise you’ll have to define your own list type if you can create something akin to cons cells
  • Or you could do it like TCL and embed them in strings…

Hash Tables

  • Use a list/array of pairs instead
  • If your hash tables have limitations, such as string keys only, that shouldn’t be an issue because MAL only makes use of strings and keywords in maps (so the keyword hack with encoding them in a string should work)
  • A more severe limitation is the objects stored in them being limited to integers, this would essentially force you to fake pointers (by coming up with a number for each known object and having an array where access to that numbered slot results in the object)

Measuring time

Extensible objects

  • The neatest way to implement MAL is by extending built-in types by the necessary fields (usually just the meta one as type/value should already be determinable) and defining extra types as needed (like for atoms and func objects)
  • If your language doesn’t support this, the easiest way out is to create custom MAL types and wrapping the native ones in them
  • This is somewhat annoying, but makes debugging a lot less painful

Testing these features

Create a directory for the language you wish to test and the following files, with .qx being the canonical file extension of the language:

util.qx

Implement the following:

  • (read-words prompt) Prompt for words until encountering EOF, return list
  • (the-answer) Calculate 42 in a convoluted way
  • (make-greeter name) Return a greeter function that returns a personalized greeting
  • (hostname) Read /etc/hostname and return its contents
  • (argv) Return command-line arguments without the program name
  • (fail-gracefully) Throw and catch user-defined exceptions
  • (splat op args) Apply the operator to the list of arguments
  • (tokenize input) Tokenize parenthesized math (you may use regex)
  • (keys dict) Return keys of map
  • (now) Return a relative point in time in ms
  • (rect size) (rect-size r) (rect-size-set! r) OOP, alternatively do the last one functionally and return a new rect with different size

test.qx

  • Import util.qx (relatively to test.qx)
  • Measure starting time
  • Test everything from util.qx
  • Measure end time
  • Print spent time

run

  • Execute test.qx from current and parent directory
  • Test with and without passed args

Makefile

  • Optional, intended for languages requiring a compilation step
  • May be used to auto-generate symlinks, configuration files and whatnot

repl.qx

  • Optional, used to show off a working readline interface

repl

  • A shell script executing repl.qx or a binary built from repl.qx

About

Languages I consider implementing MAL in

License:Other


Languages

Language:C 28.1%Language:Fortran 10.8%Language:Vala 5.3%Language:Makefile 5.1%Language:Slash 4.4%Language:Limbo 4.4%Language:Chapel 4.2%Language:Shell 4.1%Language:NewLisp 4.1%Language:ColdFusion 4.1%Language:Emacs Lisp 3.7%Language:Red 3.3%Language:Pike 3.3%Language:Standard ML 3.2%Language:ActionScript 3.2%Language:Common Lisp 3.0%Language:SuperCollider 2.1%Language:Rebol 2.0%Language:AngelScript 0.8%Language:C++ 0.6%Language:Dockerfile 0.2%