Ben Harris [Fri, 26 Jul 2019 21:01:36 +0000 (22:01 +0100)]
perl: Fold some simple core functions into %core::ns.
Ben Harris [Fri, 26 Jul 2019 20:35:52 +0000 (21:35 +0100)]
perl: Tidy up whitespace in table of core functions.
Ben Harris [Fri, 26 Jul 2019 20:14:47 +0000 (21:14 +0100)]
perl: Fold _dissoc_BANG into dissoc and simplify.
I particular, Perl allows for batch deletion of hash elements, so we can
delete all the unwanted keys at once.
Ben Harris [Fri, 26 Jul 2019 19:48:31 +0000 (20:48 +0100)]
perl: Use List::Util::pairs instead of "for (;;)" in 'let*' and 'assoc'.
Joel Martin [Fri, 26 Jul 2019 05:15:39 +0000 (00:15 -0500)]
basic: args file that doesn't rely on return value.
Instead, the file itself does the def of -*ARGS*-. The behavior that
the final value of a loaded file is returned is not necessarily
something we want to assume.
Joel Martin [Fri, 26 Jul 2019 05:14:41 +0000 (00:14 -0500)]
Merge pull request #430 from bjh21/bjh21-perl
perl: Idiomaticity improvements (and some bug fixes too)
Ben Harris [Thu, 25 Jul 2019 22:50:58 +0000 (23:50 +0100)]
perl: Clone functions before turning them into macros.
This ensures that the original function can still be used as a function
if need be (and fixes a soft test failure).
Ben Harris [Thu, 25 Jul 2019 22:36:57 +0000 (23:36 +0100)]
perl: Overload '@{}' and '%{}' on Nil.
This means that various core functions that used to special-case $nil
can now just treat it as a list or a hash-map and it will behave like
one.
Ben Harris [Thu, 25 Jul 2019 22:28:18 +0000 (23:28 +0100)]
perl: Take advantage of all mal values' being true to simplify code.
Where a function retrieves a mal value from a collection, use '||' to
provide the default case rather than checking the index or hash key in
advance. This requires that all mal values (even $false) be true in
Perl, but EVAL already requires that.
Ben Harris [Thu, 25 Jul 2019 22:03:53 +0000 (23:03 +0100)]
perl: Replace 'scalar(@x) > 0' with simply '@x'.
Using an array in a boolean context to check if it's non-empty is a
common Perl idiom.
There are still explicit uses of 'scalar' to get the precise length of
arrays, because I think the implicit behaviour there might be confusing.
Ben Harris [Thu, 25 Jul 2019 22:01:10 +0000 (23:01 +0100)]
perl: Remove a completely useless use of 'scalar'.
Ben Harris [Thu, 25 Jul 2019 21:44:01 +0000 (22:44 +0100)]
perl: Don't use regexps in 'when' clauses to match fixed strings.
Ben Harris [Thu, 25 Jul 2019 21:32:31 +0000 (22:32 +0100)]
perl: Replace %core::core_ns with %core::ns.
This follows the naming scheme recommended by the guide, and seems
natural in Perl.
Ben Harris [Thu, 25 Jul 2019 21:11:37 +0000 (22:11 +0100)]
perl: Turn $core_ns into %core_ns.
I found myself assuming it was the latter, which is a pretty good sign
it's unidiomatic.
Ben Harris [Thu, 25 Jul 2019 20:53:46 +0000 (21:53 +0100)]
perl: Don't accidentally put a load of rubbish in $repl_env.
In Perl, iterating over a hash gets you both the keys and the values, so
you need to explicitly use 'keys' if you only want the keys.
Ben Harris [Thu, 25 Jul 2019 20:25:23 +0000 (21:25 +0100)]
perl: Stylistic cleanup of indirect function calls (apply, macroexpand, etc).
Generally use temporary arrays and "shift" rather than slicing, and
leave out braces on dereference operations where that's sensible. I
haven't used the $f->{@args} syntax because I think &$f(@args) is
clearer.
Ben Harris [Thu, 25 Jul 2019 10:06:40 +0000 (11:06 +0100)]
perl: Clarify and slightly simplify 'conj' implementation.
It was confusing having $lst and $new_lst which could potentially be
vectors, so call them $seq and $new_seq instead. Also use 'shift' to
pull the first argument off @_ and then re-use @_ rather than using an
additional variable.
Ben Harris [Thu, 25 Jul 2019 10:01:27 +0000 (11:01 +0100)]
perl: Simplify definition of 'apply'.
Rather than mucking about with slices, just use 'shift' and 'pop' to
extract the first and last argument.
Ben Harris [Thu, 25 Jul 2019 09:50:47 +0000 (10:50 +0100)]
perl: Unwrap many core functions.
The change of calling conventions meant that many of the core functions
were now trivial wrappers around their implementations. Unwrap them,
reducing the number of layers of function call required.
Ben Harris [Thu, 25 Jul 2019 09:39:44 +0000 (10:39 +0100)]
perl: Change calling convention to use variadic functions.
Till now, the arguments to each function at the mal layer were passed to
the corresponding function at the perl layer as a single List argument.
This necessitated a lot of dereferencing in the core functions and was
also contrary to the process guide which recommends using variadic
functions.
Since perl functions are intrinsically variadic, this change makes the
code somewhat simpler, and enables further simplifications.
Ben Harris [Wed, 24 Jul 2019 23:42:38 +0000 (00:42 +0100)]
perl: Simplify dereference overloading of FunctionRef.
It now just pulls out the 'code' field rather than indirecting through
the 'apply' method, which in turn means that the 'apply' method can be
removed.
Ben Harris [Wed, 24 Jul 2019 22:56:09 +0000 (23:56 +0100)]
perl: Make HashMaps look like hashrefs by overloading '%{}'.
The fact that HashMaps actually are hashrefs necessitates a few "no
overloading" pragmas to allow access to the implementation, but this
fiddliness is outweighed by the improvements everywhere else in the
code.
Ben Harris [Wed, 24 Jul 2019 22:33:05 +0000 (23:33 +0100)]
perl: Make atoms look like scalar refs by overloading '${}'.
This reduces the number of things that need to know about '->{val}'.
Ben Harris [Wed, 24 Jul 2019 21:54:27 +0000 (22:54 +0100)]
perl: Fix a couple of lurking occurences of ->{val} on Sequences.
Ben Harris [Wed, 24 Jul 2019 21:30:56 +0000 (22:30 +0100)]
perl: Use constant string matches for matching symbols, not regexps.
Ben Harris [Wed, 24 Jul 2019 21:19:44 +0000 (22:19 +0100)]
perl: Remove unnecessary pragmata allowing use of given/when.
Some files no longer use them at all.
Ben Harris [Thu, 25 Jul 2019 22:24:36 +0000 (23:24 +0100)]
perl: Fix a lurking 'ref' that should have been 'isa'.
Ben Harris [Wed, 24 Jul 2019 21:10:08 +0000 (22:10 +0100)]
perl: Replace most remaining uses of "ref" with "isa".
The hold-outs are testing incoming Perl values from interop (fine),
checking if some things are a reference at all (also fine), and
comparing the types of objects in _equal_Q() (slightly iffy).
Ben Harris [Wed, 24 Jul 2019 20:43:19 +0000 (21:43 +0100)]
perl: Bless all coderefs used as mal values.
They're all blessed into a new class, CoreFunction, and everything that
used to look for CODE now looks for CoreFunction instead.
Ben Harris [Wed, 24 Jul 2019 20:21:42 +0000 (21:21 +0100)]
perl: Convert metadata access into a method.
This allows for having it work differently on core functions.
Ben Harris [Wed, 24 Jul 2019 20:12:44 +0000 (21:12 +0100)]
perl: Support (and use) '&{}' overloading on Function and FunctionRef.
This means that all kinds of function can be called as though they're
coderefs, whether or not they actually are, meaning fewer switches on
the internal types of functions.
Ben Harris [Wed, 24 Jul 2019 10:01:37 +0000 (11:01 +0100)]
perl: Use Perl's flexible quoting operators when embedding mal code.
This allows us to avoid the need to backslash embedded apostrophes
and quotation marks.
Ben Harris [Wed, 24 Jul 2019 09:21:10 +0000 (10:21 +0100)]
perl: Much less complicated implementations of 'cons' and 'concat'.
Ben Harris [Wed, 24 Jul 2019 00:06:09 +0000 (01:06 +0100)]
perl: In step 2, initialise $repl_env all at once.
That's what the guide suggests we should do, and is more idiomatic perl.
Ben Harris [Tue, 23 Jul 2019 23:54:58 +0000 (00:54 +0100)]
perl: Avoid using "ref" to check the type of objects. Use "isa" instead.
This ensures that we handle subclassing correctly. Unfortunately this
breaks a little in the area of core functions because they're passed
around as unblessed code references. I think this will be best fixed by
blessing them.
Ben Harris [Tue, 23 Jul 2019 23:35:40 +0000 (00:35 +0100)]
perl: Explicitly detect empty lists before macro expansion.
A future change will mean that implicitly handling this case won't work.
Ben Harris [Tue, 23 Jul 2019 22:30:05 +0000 (23:30 +0100)]
perl: Take advantage of the overload of '@{}' on Sequences.
This is mostly replacing @{$X->{val}} with @$X.
Ben Harris [Tue, 23 Jul 2019 21:06:56 +0000 (22:06 +0100)]
perl: Overload '@{}' on mal sequences and thus remove Sequence::nth.
I think it's more idiomatic perl for mal sequences to look like listrefs
even if under the covers they're actually hashrefs. It means that
indexing doesn't need an explicit method call, so A->nth(B) becomes
A->[B].
Ben Harris [Tue, 23 Jul 2019 20:25:20 +0000 (21:25 +0100)]
perl: Factor out common features of Vectors and Lists into a superclass.
The two classes are identical apart from their names.
Joel Martin [Thu, 25 Jul 2019 04:41:10 +0000 (23:41 -0500)]
guile: disable non-recursive test.
The non-recursive TCO test case specific to guile causes regress mode
to fail when using stepA to regress step5 because stepA does not have
the artificial stack size restriction contained in only step5. There
is no reason to artificially restrict implementation call stack in
order to pass the non-TCO calls so just remove that guile specific
test case.
Joel Martin [Wed, 24 Jul 2019 06:29:40 +0000 (01:29 -0500)]
Regress test of deferrables. Fix dart, factor.
Add a regression run to Travis that enables hard deferrables but
omits optionals so that we can test to make sure that all the
requirements are met for self-hosting in stepA.
Cleanup up some of the soft/deferrable/optional markings.
Deferrables are what will be needed eventually to self host but aren't
needed for the immediate next steps. Optional aren't even needed for
self-hosting but are nice things to have.
Also:
- Sync dart step9 and stepA with step8. Do not eval macroexpanded
forms in macroexpand form.
- Fix stepA of factor which was missing some fixes from step9.
- Increase test timeouts in top-level Makefile for guile and io.
Joel Martin [Wed, 24 Jul 2019 16:18:26 +0000 (11:18 -0500)]
Merge pull request #427 from dubek/ocaml-fix-unterminated-string
ocaml: Fix reading of unterminated strings that happen to end with '"'.
Joel Martin [Wed, 24 Jul 2019 16:17:41 +0000 (11:17 -0500)]
Merge pull request #428 from dubek/io-fix-escape-slash
io: Fix unneeded escaping of forward slash
Dov Murik [Tue, 23 Jul 2019 07:21:27 +0000 (10:21 +0300)]
io: Fix unneeded escaping of forward slash
Instead of using Io's `asJson` method which escapes forward slashes,
implement our own string escaping code so it fits the Mal requirements.
The relevant step1 test was modified from soft to hard.
Dov Murik [Tue, 23 Jul 2019 06:46:43 +0000 (09:46 +0300)]
ocaml: Fix reading of unterminated strings that happen to end with '"'.
Issue #359
Joel Martin [Sun, 21 Jul 2019 23:40:59 +0000 (18:40 -0500)]
Merge pull request #426 from dubek/extra-step4-tests
tests: step4: Add optional list and vector equality tests
Joel Martin [Sun, 21 Jul 2019 23:24:10 +0000 (18:24 -0500)]
Merge pull request #425 from dubek/io-fixes
Io fixes
Dov Murik [Sun, 21 Jul 2019 10:10:17 +0000 (13:10 +0300)]
tests: Add optional list and vector eqaulity tests
Dov Murik [Sun, 21 Jul 2019 07:54:05 +0000 (10:54 +0300)]
io: Atoms can have meta
Dov Murik [Sun, 21 Jul 2019 07:54:00 +0000 (10:54 +0300)]
io: Don't mutate existing function when defining a macro
Dov Murik [Sun, 21 Jul 2019 07:53:54 +0000 (10:53 +0300)]
io: keyword and symbol accept a keyword/symbol argument
Dov Murik [Sun, 21 Jul 2019 07:53:41 +0000 (10:53 +0300)]
io: Fix list and vector equality
Previously we relied on Io's list equality, but this doesn't hold for
non-primitive elements in the list, so (= [:abc] [:abc]) returned false.
Joel Martin [Thu, 18 Jul 2019 17:50:38 +0000 (12:50 -0500)]
Merge pull request #424 from asarhaddon/typo-test-alias-hacks
tests/lib: fix path in test-alias-hacks, use load-file-once
Nicolas Boulenguez [Thu, 18 Jul 2019 15:50:12 +0000 (17:50 +0200)]
tests/lib: fix path in test-alias-hacks, use load-file-once
Joel Martin [Wed, 17 Jul 2019 23:05:54 +0000 (18:05 -0500)]
Merge pull request #423 from asarhaddon/trivial-from-401
Trivial commits from 401
Joel Martin [Wed, 17 Jul 2019 23:03:10 +0000 (18:03 -0500)]
Merge pull request #361 from asarhaddon/exercise-native-implementations
Draft exercise, native implementations of some built-in functions.
Nicolas Boulenguez [Sun, 23 Jun 2019 16:21:58 +0000 (18:21 +0200)]
scheme: allow keyword argument for keyword built-in
Nicolas Boulenguez [Sun, 23 Jun 2019 15:03:20 +0000 (17:03 +0200)]
tests: non alphanumeric characters in input
Make: remove part of EVAL breaking # and $
step0: no MAL character must break the interpreter
(soft) no printable ASCII character either
step1: no MAL character must break strings
(soft) no printable ASCII character should break strings
(soft) no character should break comments
step6: redo step1 tests for comments inside read-string, as new
problem may occur with line breaks and escape characters of the host
language.
Nicolas Boulenguez [Sun, 23 Jun 2019 14:59:07 +0000 (16:59 +0200)]
elixir: add catch-all stanza in with-meta
Nicolas Boulenguez [Sun, 2 Jun 2019 11:34:45 +0000 (13:34 +0200)]
tests: remove commented test for 10th Fibonnacci number
Nicolas Boulenguez [Sun, 2 Jun 2019 11:26:37 +0000 (13:26 +0200)]
tests: soft-tests for keywords (instead of comments)
Nicolas Boulenguez [Sun, 2 Jun 2019 11:23:34 +0000 (13:23 +0200)]
tests: soft-test metadata for atoms
Nicolas Boulenguez [Sun, 2 Jun 2019 11:18:33 +0000 (13:18 +0200)]
make/readline (trivial): split the line containing 7 shell commands
Nicolas Boulenguez [Sun, 2 Jun 2019 11:17:41 +0000 (13:17 +0200)]
lib/perf.mal (trivial): println instead of prn and str
Nicolas Boulenguez [Sun, 2 Jun 2019 11:16:36 +0000 (13:16 +0200)]
ada.2: let keyword function accept a keyword argument
Joel Martin [Wed, 17 Jul 2019 20:02:36 +0000 (15:02 -0500)]
Merge pull request #420 from asarhaddon/load-file-once
lib/load-file-once: basic support for multiple imports
Nicolas Boulenguez [Wed, 17 Jul 2019 09:01:02 +0000 (11:01 +0200)]
exercises: progressive solution for let*
Joel Martin [Wed, 17 Jul 2019 06:36:40 +0000 (01:36 -0500)]
Merge pull request #422 from bendudson/nasm-fix
NASM: Fix bug in str when appending empty arrays
Ben Dudson [Wed, 17 Jul 2019 05:42:45 +0000 (06:42 +0100)]
Fix bug in str when appending empty arrays
The `slurp` function can produce strings which end with an empty
Array, if the input file is a multiple of the Array size. When
appending such a string, `string_append_string` would keep reading
past the end of the string, and continue until it ran out of
memory. This fix adds a check for empty Array.
Joel Martin [Tue, 16 Jul 2019 20:37:34 +0000 (15:37 -0500)]
Merge pull request #421 from sgtatham/eval-ast-vector-gc-fix
vala: avoid half-constructed vectors being garbage-collected.
Simon Tatham [Tue, 16 Jul 2019 20:10:02 +0000 (21:10 +0100)]
vala: avoid half-constructed vectors being garbage-collected.
The clause in eval_ast() which evaluates each element of an input
vector into an output vector was holding the intermediate results in
an ordinary GLib.List, and putting them all into a vector at the end
of the evaluation. But that meant that nothing was preventing all
those values from being garbage-collected half way through.
Now we make an output Mal.Vector at the start of the process, and
point a GC.Root at it to ensure it stays around until we've finished
putting items in it.
This fixes the vala part of #418, I think.
Nicolas Boulenguez [Sun, 2 Jun 2019 13:35:54 +0000 (15:35 +0200)]
lib/load-file-once: basic support for multiple imports
Joel Martin [Mon, 15 Jul 2019 21:51:52 +0000 (16:51 -0500)]
Merge pull request #419 from asarhaddon/vala-remove-redundant-parameter
vala: remove a redundant parameter
Nicolas Boulenguez [Mon, 15 Jul 2019 20:46:55 +0000 (22:46 +0200)]
vala: remove a redundant parameter
Joel Martin [Mon, 15 Jul 2019 20:21:15 +0000 (15:21 -0500)]
Merge pull request #400 from asarhaddon/improve-mal-impl-macro-no-meta
Improve mal impl macro no meta
Nicolas Boulenguez [Mon, 15 Jul 2019 17:49:33 +0000 (19:49 +0200)]
Merge remote-tracking branch 'remotes/kanaka/master' into improve-mal-impl-macro-no-meta
Nicolas Boulenguez [Mon, 15 Jul 2019 17:46:10 +0000 (19:46 +0200)]
mal: implement macro? with contains? instead of list equality
This is more efficient, and avoids triggering some bugs (see #400).
Joel Martin [Mon, 15 Jul 2019 16:41:08 +0000 (11:41 -0500)]
Merge pull request #417 from asarhaddon/slurp-twice
check that slurp works twice in a row. Fix rexx
Nicolas Boulenguez [Mon, 15 Jul 2019 15:50:47 +0000 (17:50 +0200)]
check that slurp works twice in a row. Fix rexx
Joel Martin [Mon, 15 Jul 2019 15:02:05 +0000 (10:02 -0500)]
r: add step deps on rdyncall lib install.
Joel Martin [Mon, 15 Jul 2019 15:01:03 +0000 (10:01 -0500)]
powershell: prn/println return explicit null.
This is needed for self-hosting to pass all tests.
Joel Martin [Mon, 15 Jul 2019 05:01:16 +0000 (00:01 -0500)]
Merge pull request #416 from bjh21/bjh21-equal-empty
step 4: Test that (= (list nil) (list)) returns false.
Nicolas Boulenguez [Sun, 14 Jul 2019 15:07:44 +0000 (17:07 +0200)]
Implement macros with maps instead of vectors.
Output of macros will probably be more readable.
Inline _macro_wrap and _unwrap for efficiency (there are less
primitive operations for maps than for vectors).
Basic check of `map?` and `macro?`. Swap them in order to simplify the
diff with
cb9b0654.
Ben Harris [Sat, 13 Jul 2019 11:08:05 +0000 (12:08 +0100)]
step 4: Test that (= (list nil) (list)) returns false.
Certain naïve implementations of '=' (like the one I just wrote) will
get this wrong.
Nicolas Boulenguez [Tue, 9 Jul 2019 01:21:34 +0000 (03:21 +0200)]
mal: fix vector? sequential? and PRINT for new macro implementation
Nicolas Boulenguez [Sat, 15 Jun 2019 16:10:18 +0000 (18:10 +0200)]
scheme: fix syntax error in
5e5d489
Nicolas Boulenguez [Sat, 15 Jun 2019 15:05:46 +0000 (17:05 +0200)]
mal: implement macro without metadata
Support for metadata becomes optional.
Support for fn? becomes optional again, reverting
5e5d4892.
Nicolas Boulenguez [Tue, 4 Jun 2019 12:28:55 +0000 (14:28 +0200)]
guile, scheme: fix fn? when metadata contains "ismacro"
Let `with-meta f m` create a function even if f is a macro, instead of
setting an "ismacro" metadata that is never used again (and breaks
self-hosting).
Also move the test for fn? from Optional to Deferrable, the function
is used for self-hosting.
Nicolas Boulenguez [Tue, 4 Jun 2019 09:22:25 +0000 (11:22 +0200)]
mal: in step2, revert to reporting key error
Unlike the one in `env.mal`, the `get` built-in used during step2
returns `nil`, so the MAL implementation must throw an error.
Nicolas Boulenguez [Fri, 31 May 2019 12:33:17 +0000 (14:33 +0200)]
mal: modify lib/ in order to hide bugs in make/ and guile/
Make: avoid # character.
Guile: avoid `unquote` inside a vector inside a list inside `quasiquote`.
The bug in scheme/ is most probably the same.
Nicolas Boulenguez [Thu, 30 May 2019 17:27:45 +0000 (19:27 +0200)]
mal: rename macro? to _macro?. Also rename bool-and in lib/equality.mal.
Nicolas Boulenguez [Wed, 22 May 2019 18:45:57 +0000 (20:45 +0200)]
Remove gensym, inc and or from step files.
* Move `gensym` and `inc` from step files to `lib/trivial.mal`.
* Move `or` from step files to `lib/test_cascade.mal`.
Shorten it because `(first ())` returns `nil`
* Update process and tests accordingly (not the figures yet).
Nicolas Boulenguez [Wed, 22 May 2019 09:13:42 +0000 (11:13 +0200)]
mal: improve MAL implementation.
Generally: remove variables used only once with generic names,
introduce a variable when the same result is computed twice.
core_rs: replace strings with symbols because it is more consistent with
the public interface of `env.mal`
bind-env:
- compare with '& instead of "&", avoiding a conversion per iteration
- compute `first` once, store the result
env-find:
- move `if env` at start of recursion, avoiding to `get` in a row.
stepA_mal:
- eval-ast, eval: remove duplicate `do`
- LET: move `form` into the signature. The recursion does not change much,
but the initial call is shorter and more intuitive.
- EVAL:
- remove initial (not (list? ast)) test, which was redundant
(MACROEXPAND would do nothing).
- replace (nil? (first ast)) with (empty? ast), more explicit
(also, `(nil 1)` is now reported as incorrect
- `try*`: stop checking that first component of optional argument is
`catch*`. No other user input is checked explicitly.
- repl-loop: a slight modification avoids to create a new environment
depth for each new line.
Joel Martin [Tue, 9 Jul 2019 01:36:40 +0000 (20:36 -0500)]
Merge pull request #408 from asarhaddon/haskell-style
Haskell: make the code more readable and idiomatic
Joel Martin [Tue, 9 Jul 2019 01:33:59 +0000 (20:33 -0500)]
Merge pull request #414 from bjh21/bjh21-php-hashmap
php: Make sure that hashmap keys get returned as strings
Nicolas Boulenguez [Thu, 4 Jul 2019 21:50:04 +0000 (23:50 +0200)]
haskell: remove the need for unsafePerformIO type forced conversion
Nicolas Boulenguez [Thu, 4 Jul 2019 14:43:35 +0000 (16:43 +0200)]
haskell: shorten Reader with Applicative instead of Monad
Nicolas Boulenguez [Thu, 4 Jul 2019 10:49:44 +0000 (12:49 +0200)]
haskell: drop redundant import, test empty repl line once
Nicolas Boulenguez [Thu, 4 Jul 2019 08:28:07 +0000 (10:28 +0200)]
haskell: rewrite nth without old-style partial function
Nicolas Boulenguez [Thu, 4 Jul 2019 08:23:30 +0000 (10:23 +0200)]
haskell: adapt quasiquote to existing test, drop redundant import