jackhill/mal.git
4 years agoMerge pull request #439 from bjh21/bjh21-perl
Joel Martin [Sun, 4 Aug 2019 19:27:15 +0000 (14:27 -0500)]
Merge pull request #439 from bjh21/bjh21-perl

Final (?) perl improvements

4 years agoperl: Add a README file containing some facts.
Ben Harris [Sun, 4 Aug 2019 16:23:26 +0000 (17:23 +0100)]
perl: Add a README file containing some facts.

4 years agoUpdate version requirement for perl.
Ben Harris [Sun, 4 Aug 2019 15:50:09 +0000 (16:50 +0100)]
Update version requirement for perl.

I don't think it's worked on perl 5.8 for a long time.

4 years agoperl: Rework 'do' to not use 'splice' and 'rest' methods.
Ben Harris [Sat, 3 Aug 2019 21:53:36 +0000 (22:53 +0100)]
perl: Rework 'do' to not use 'splice' and 'rest' methods.

I feel that it's more perly to directly use Perl's array manipulation
functions.  It's certainly more consistent with the other special forms.

4 years agoperl: Replace $a1, $a2, and $a3 in EVAL with usefully-named veriables.
Ben Harris [Tue, 30 Jul 2019 20:40:31 +0000 (21:40 +0100)]
perl: Replace $a1, $a2, and $a3 in EVAL with usefully-named veriables.

This means that most of the special forms have an assignment at the top
giving names to the members of @$ast.  I think this makes the code a
little more readable.

4 years agoperl: Use a proper Mal::Keyword type.
Ben Harris [Tue, 30 Jul 2019 19:41:13 +0000 (20:41 +0100)]
perl: Use a proper Mal::Keyword type.

Representing a keyword as a Mal::String with a magic first character was
beginning to annoy me, so instead create a proper Mal::Keyword class.
To support using both Mal::String and Mal::Keyword as hash keys,
overload stringification on all Mal::Scalar subclasses.

This means that now instead of a Mal::String stringifying to something
like "Mal::String=SCALAR(0x5744ea58)", it will stringify to something
more like "Mal::String abc", which is readable, has the correct
properties for a hash-map key, and is easy to convert back into a
Mal::String.

This turns out to work perfectly well, and entirely accidentally
arranges that 'keyword' now works properly when fed a keyword as input.

4 years agomake: revert/correct fix for plain undef symbol.
Joel Martin [Fri, 2 Aug 2019 17:44:22 +0000 (12:44 -0500)]
make: revert/correct fix for plain undef symbol.

The return value from _error was causing some breakage in other error
handling. Instead, return a value from the spot where the undefined
symbol error is set. This achieves the desired fix without breaking
other unclosed sequence errors.

4 years agograph: update bbc-basic. Exclude more from LOC.
Joel Martin [Fri, 2 Aug 2019 16:39:18 +0000 (11:39 -0500)]
graph: update bbc-basic. Exclude more from LOC.

Pull in bbc-basic update that allows loccount to properly count the
files.
Exclude more documentation and configuration files from LOC counts.

4 years agoMerge pull request #438 from bjh21/bjh21-bbc-basic
Joel Martin [Fri, 2 Aug 2019 15:44:48 +0000 (10:44 -0500)]
Merge pull request #438 from bjh21/bjh21-bbc-basic

bbc-basic: Switch to filenames ending ".bas".

4 years agobbc-basic: Changes consequent upon file renaming.
Ben Harris [Thu, 1 Aug 2019 22:24:40 +0000 (23:24 +0100)]
bbc-basic: Changes consequent upon file renaming.

To allow the same BASIC source (and in particular, LIBRARY statements)
to work on both Unix and RISC OS (the latter of which doesn't allow '.'
in file names), create symlinks to all the libraries from their
unadorned names.

4 years agobbc-basic: Rename all files of BASIC code to *.bas.
Ben Harris [Thu, 1 Aug 2019 22:22:53 +0000 (23:22 +0100)]
bbc-basic: Rename all files of BASIC code to *.bas.

This should help things to recognise what they are.  Consequential
amendments in the next commit.

This also removes toktest, which is unnecessary now.

4 years agograph: BASICs are statically typed.
Joel Martin [Wed, 31 Jul 2019 18:58:31 +0000 (13:58 -0500)]
graph: BASICs are statically typed.

4 years agodocs/graph: add bbc-basic, vala. General updates.
Joel Martin [Wed, 31 Jul 2019 17:11:53 +0000 (12:11 -0500)]
docs/graph: add bbc-basic, vala. General updates.

Incorporates fixed LOC stats that correctly ignores steps 0-9 and
ignores generated files and external downloaded dependencies.

4 years agostats: exclude steps 0-9 & generated/extern files
Joel Martin [Wed, 31 Jul 2019 05:10:27 +0000 (00:10 -0500)]
stats: exclude steps 0-9 & generated/extern files

4 years agomake: fix catch of undefined plain symbol
Joel Martin [Wed, 31 Jul 2019 05:06:37 +0000 (00:06 -0500)]
make: fix catch of undefined plain symbol

The _error function was returning an empty string which meant that in
the try*/catch* implementation, the lack of result was preventing
foreach from being used as a "let" form and because of that it was
skipping the catch* handling path.

4 years agoMerge pull request #359 from bjh21/bjh21-unterminated-strings
Joel Martin [Wed, 31 Jul 2019 14:24:08 +0000 (09:24 -0500)]
Merge pull request #359 from bjh21/bjh21-unterminated-strings

New test for reading an unterminated string that nonetheless ends with a quotation mark

4 years agoMerge pull request #436 from dubek/vhdl-fix-unterminated-strings
Joel Martin [Wed, 31 Jul 2019 14:22:23 +0000 (09:22 -0500)]
Merge pull request #436 from dubek/vhdl-fix-unterminated-strings

vhdl: Fix reading of unterminated strings that happen to end with '"'.

4 years agovhdl: Fix reading of unterminated strings that happen to end with '"'.
Dov Murik [Wed, 31 Jul 2019 12:11:34 +0000 (15:11 +0300)]
vhdl: Fix reading of unterminated strings that happen to end with '"'.

Issue #359

4 years agofactor: detect unclosed strings.
Joel Martin [Wed, 31 Jul 2019 04:58:48 +0000 (23:58 -0500)]
factor: detect unclosed strings.

Detect strings that are not properly terminated.

4 years agoperl6, r, skew: detect unclosed strings.
Joel Martin [Wed, 31 Jul 2019 04:46:36 +0000 (23:46 -0500)]
perl6, r, skew: detect unclosed strings.

Detect strings that are not properly terminated.

4 years agoswift: detect unclosed strings.
Joel Martin [Wed, 31 Jul 2019 03:36:40 +0000 (22:36 -0500)]
swift: detect unclosed strings.

Detect strings that are not properly terminated.

4 years agowasm: check for invalid string in read_form
Joel Martin [Wed, 31 Jul 2019 04:10:44 +0000 (23:10 -0500)]
wasm: check for invalid string in read_form

4 years agorpython, swift3, wasm: detected unclosed strings.
Joel Martin [Wed, 31 Jul 2019 03:26:50 +0000 (22:26 -0500)]
rpython, swift3, wasm: detected unclosed strings.

Detect more cases where strings are unterminated.

4 years agoguile, matlab, nim, ps: detected unclosed strings.
Joel Martin [Wed, 31 Jul 2019 03:26:18 +0000 (22:26 -0500)]
guile, matlab, nim, ps: detected unclosed strings.

Detect more cases where strings are unterminated.

4 years agocoffee, dart, elixir, elm: detect unclosed strings.
Joel Martin [Wed, 31 Jul 2019 03:25:17 +0000 (22:25 -0500)]
coffee, dart, elixir, elm: detect unclosed strings.

Detect more cases of strings being unterminated.

4 years agoMerge pull request #435 from bjh21/bjh21-perl
Joel Martin [Tue, 30 Jul 2019 15:16:40 +0000 (10:16 -0500)]
Merge pull request #435 from bjh21/bjh21-perl

perl: New metadata and TCO and other changes

4 years agoperl: Remove a temporary variable in functions defined by 'fn*'.
Ben Harris [Tue, 30 Jul 2019 09:08:13 +0000 (10:08 +0100)]
perl: Remove a temporary variable in functions defined by 'fn*'.

I'm in favour of meaningful names for the members of @_, but naming a
reference to @_ "$args" really doesn't gain much.

4 years agoperl: Use // instead of ?: when evaluating "else" clause of 'if'.
Ben Harris [Tue, 30 Jul 2019 08:59:32 +0000 (09:59 +0100)]
perl: Use // instead of ?: when evaluating "else" clause of 'if'.

4 years agoperl: Simplify string unescaping code.
Ben Harris [Mon, 29 Jul 2019 23:56:11 +0000 (00:56 +0100)]
perl: Simplify string unescaping code.

4 years agoperl: Sightly simplify 'swap!'.
Ben Harris [Mon, 29 Jul 2019 23:43:54 +0000 (00:43 +0100)]
perl: Sightly simplify 'swap!'.

4 years agoperl: Use '//' operator to make pr_str slightly simpler.
Ben Harris [Mon, 29 Jul 2019 23:25:17 +0000 (00:25 +0100)]
perl: Use '//' operator to make pr_str slightly simpler.

4 years agoperl: Use pairmap to make printing hash-maps simpler.
Ben Harris [Mon, 29 Jul 2019 23:21:56 +0000 (00:21 +0100)]
perl: Use pairmap to make printing hash-maps simpler.

Also tidy up printing code for sequences a little.

4 years agoperl: Use more string interpolation in the printer.
Ben Harris [Mon, 29 Jul 2019 23:07:43 +0000 (00:07 +0100)]
perl: Use more string interpolation in the printer.

4 years agoperl: Avoid substr in favour of $1 and $'.
Ben Harris [Mon, 29 Jul 2019 23:02:56 +0000 (00:02 +0100)]
perl: Avoid substr in favour of $1 and $'.

It just seems more perlish to use regexps where they're sensible.

4 years agoperl: Remove experimental given/when syntax from interop.pm.
Ben Harris [Mon, 29 Jul 2019 23:01:15 +0000 (00:01 +0100)]
perl: Remove experimental given/when syntax from interop.pm.

It doesn't gain anything over for/if, and removing it avoids a warning.

4 years agoperl: Avoid excessive copying in Mal::Sequence::rest and ::slice.
Ben Harris [Mon, 29 Jul 2019 19:54:02 +0000 (20:54 +0100)]
perl: Avoid excessive copying in Mal::Sequence::rest and ::slice.

There's no need to copy the input into @arr and then copy the bits we
care about into the output array.

4 years agoperl: Replace _string_Q with ->isa('Mal::String') && !->isa('Mal::Keyword')
Ben Harris [Mon, 29 Jul 2019 19:43:29 +0000 (20:43 +0100)]
perl: Replace _string_Q with ->isa('Mal::String') && !->isa('Mal::Keyword')

That's a bit ugly, but it gets rid of the last type-predicate function.

4 years agoperl: Replace _keyword with Mal::Keyword->new.
Ben Harris [Mon, 29 Jul 2019 19:36:12 +0000 (20:36 +0100)]
perl: Replace _keyword with Mal::Keyword->new.

It's not really a constructor for Mal::Keyword (because there's no such
class), but it looks similar enough for most purposes.

4 years agoperl: Replace _keyword_Q with ->isa('Mal::Keyword').
Ben Harris [Mon, 29 Jul 2019 19:26:19 +0000 (20:26 +0100)]
perl: Replace _keyword_Q with ->isa('Mal::Keyword').

There isn't actually a Mal::Keyword class, but perl lets us override
"isa" so we can pretend there is.

4 years agoperl: Enhance Mal::HashMap::new to take an array reference. Use this.
Ben Harris [Sun, 28 Jul 2019 22:50:22 +0000 (23:50 +0100)]
perl: Enhance Mal::HashMap::new to take an array reference.  Use this.

This replaces _hash_map and has the nice feature that it looks just like
the constructors for Mal::List and Mal::Vector, so the reader can treat
them all the same.

4 years agoperl: Abolish most of the type predicates in favour of ->isa().
Ben Harris [Sun, 28 Jul 2019 16:58:07 +0000 (17:58 +0100)]
perl: Abolish most of the type predicates in favour of ->isa().

_string_Q and _keyword_Q survive because they distinguish two mal types
that are represented by the same Perl class.

4 years agoperl: Abolish most of the complexity of function classes.
Ben Harris [Sun, 28 Jul 2019 15:52:49 +0000 (16:52 +0100)]
perl: Abolish most of the complexity of function classes.

Now there's just Mal::Function, which is the old Mal::CoreFunction.
Macros are represented by Mal::Macro, a different subclass of the same
parent.

4 years agoperl: Use goto &NAME for tail-call optimisation.
Ben Harris [Sat, 27 Jul 2019 20:35:30 +0000 (21:35 +0100)]
perl: Use goto &NAME for tail-call optimisation.

This is rather contrary to the guide, which expects a loop in EVAL, but
perl is unusual in having native support for (manual) tail-call
optimisation and it would seem a shame not to take advantage of this.

This leaves macros broken since all functions are now implemented as
core functions, and we don't yet have support for turning them into
macros.

4 years agoperl: Convert sequences into blessed array references.
Ben Harris [Sat, 27 Jul 2019 09:30:45 +0000 (10:30 +0100)]
perl: Convert sequences into blessed array references.

The extra hash was only used to hold metadata.

4 years agoperl: Remove FunctionRef class.
Ben Harris [Sat, 27 Jul 2019 09:28:15 +0000 (10:28 +0100)]
perl: Remove FunctionRef class.

Now that metadata can be attached to a CoreFunction, there's no need
for the proxy class.

4 years agoperl: Convert atoms into simple scalar references.
Ben Harris [Sat, 27 Jul 2019 09:24:46 +0000 (10:24 +0100)]
perl: Convert atoms into simple scalar references.

4 years agoperl: Replace _clone() with a ->clone method.
Ben Harris [Sat, 27 Jul 2019 09:20:47 +0000 (10:20 +0100)]
perl: Replace _clone() with a ->clone method.

This means that each class is responsible for cloning itself, which
helps with encapsulation.

4 years agoperl: Simplify hash-map implementation.
Ben Harris [Sat, 27 Jul 2019 09:03:55 +0000 (10:03 +0100)]
perl: Simplify hash-map implementation.

Now that metadata is external, we can remove the layer of indirection
in the HashMap class and have the top-level hash contain the hash-map
contents.

4 years agoperl: Remove old metadata implementation.
Ben Harris [Fri, 26 Jul 2019 00:41:06 +0000 (01:41 +0100)]
perl: Remove old metadata implementation.

Several objects are now single-member hashes, which is obviously silly.

4 years agoperl: Introduce fieldhash-based metadata implementation.
Ben Harris [Fri, 26 Jul 2019 00:24:44 +0000 (01:24 +0100)]
perl: Introduce fieldhash-based metadata implementation.

Rather than attaching metadata directly to objects, hold it in a
auxiliary hash keyed by object ID.  Perl's Hash::Util::FieldHash
provides a means to do this with proper garbage-collection.  This does
mean that cloning an object no longer brings its metadata along, but I
think the only use of _clone outside of attaching metadata is to make
macros, and (for now) mal doesn't require that 'defmacro!' preserve
metadata.

This commit only adds the new metadata system.  Most of the old one is
still lying around.

4 years agoperl: Replace _sequential_Q in step files with ->isa('Mal::Sequence').
Ben Harris [Sun, 28 Jul 2019 09:58:57 +0000 (10:58 +0100)]
perl: Replace _sequential_Q in step files with ->isa('Mal::Sequence').

4 years agoSkip perf for second-order self-hosted tests.
Joel Martin [Mon, 29 Jul 2019 23:20:11 +0000 (18:20 -0500)]
Skip perf for second-order self-hosted tests.

4 years agoFix second-order self-hosting.
Joel Martin [Mon, 29 Jul 2019 22:55:25 +0000 (17:55 -0500)]
Fix second-order self-hosting.

The `_map?` function was introduced when transitioning the macro
property being stored in metadata to uinsg a regular map with
a special key. The `_map?` function causes issues in a few places but
the biggest issue is that it breaks the `_macro?` function for the
second order self-hosted mal instance. The `_macro?` function contains
a `(map? x)` call that returns false resulting in the `_macro?` call
returning false.  I'll push something later that fixes this and also
that activates second order self-hosted tests so we can catch this
sort of issue in the future.

4 years agoMerge pull request #387 from asarhaddon/test-macroexpand-no-quasiquote
Joel Martin [Mon, 29 Jul 2019 22:53:55 +0000 (17:53 -0500)]
Merge pull request #387 from asarhaddon/test-macroexpand-no-quasiquote

test macroexpand without assuming that quasiquote is a special form

4 years agoMerge pull request #415 from asarhaddon/load-file-trailing-new-line-nil
Joel Martin [Mon, 29 Jul 2019 22:42:26 +0000 (17:42 -0500)]
Merge pull request #415 from asarhaddon/load-file-trailing-new-line-nil

load-file: accept final comment without new line, return nil

4 years agoJava: fix escaping of '/'.
Joel Martin [Mon, 29 Jul 2019 14:15:17 +0000 (09:15 -0500)]
Java: fix escaping of '/'.

Switch to escapeJava which won't do escaping of forward slash.

4 years agoMerge pull request #432 from bjh21/bjh21-perl
Joel Martin [Mon, 29 Jul 2019 14:08:48 +0000 (09:08 -0500)]
Merge pull request #432 from bjh21/bjh21-perl

More perl improvements

4 years agoMerge pull request #433 from bendudson/fix-nasm-empty-args
Joel Martin [Mon, 29 Jul 2019 14:04:08 +0000 (09:04 -0500)]
Merge pull request #433 from bendudson/fix-nasm-empty-args

Fix nasm zero argument function call

4 years agoApplying changes to step6 - stepA
Ben Dudson [Sun, 28 Jul 2019 16:15:41 +0000 (17:15 +0100)]
Applying changes to step6 - stepA

Tested stepA, function with empty args still working.

4 years agoFix step 5 call function no args
Ben Dudson [Sun, 28 Jul 2019 16:03:55 +0000 (17:03 +0100)]
Fix step 5 call function no args

Previously failed on
```
((fn* () 4))

```
due to freeing the list containing the function too early.

4 years agoperl: Simplified and tightened implementation of 'try*'.
Ben Harris [Sun, 28 Jul 2019 11:43:12 +0000 (12:43 +0100)]
perl: Simplified and tightened implementation of 'try*'.

This also fixes a bug where the last character of the stringification of
an exception object might get removed.

4 years agoperl: Remove _nil_Q(), _true_Q(), and _false_Q().
Ben Harris [Sun, 28 Jul 2019 10:20:14 +0000 (11:20 +0100)]
perl: Remove _nil_Q(), _true_Q(), and _false_Q().

They were almost unused, and 'eq' is slightly more self-explanatory.

4 years agoload-file: accept empty file or final comment, return nil
Nicolas Boulenguez [Mon, 15 Jul 2019 21:57:02 +0000 (23:57 +0200)]
load-file: accept empty file or final comment, return nil

Let `load-file` append a new line in case last line contains a
comment.

Also append `nil` so that the return value is predictible. Remove the
existing explicit `nil` from existing sources.

Adapt documentation and tests.

4 years agoperl: Polish _equal_Q a little.
Ben Harris [Sun, 28 Jul 2019 09:49:00 +0000 (10:49 +0100)]
perl: Polish _equal_Q a little.

It now uses "unless" rather than "if", uses "isa" rather than
_sequential_Q, doesn't bother with temporary variables for the types
of the arguments, and doesn't special-case symbols.

4 years agoperl: Re-FATALise the "recursion" warning from step 5 onwards.
Ben Harris [Sun, 28 Jul 2019 09:13:49 +0000 (10:13 +0100)]
perl: Re-FATALise the "recursion" warning from step 5 onwards.

The step 5 tests expect that deep recursion will cause an exception, and
not just a warning, so they can prove that TCO is working properly.

4 years agoperl: Use "foreach" for variable bindings in Mal::Env::new.
Ben Harris [Sun, 28 Jul 2019 09:13:44 +0000 (10:13 +0100)]
perl: Use "foreach" for variable bindings in Mal::Env::new.

4 years agoperl: Move 'pl*' to core.pm.
Ben Harris [Sat, 27 Jul 2019 23:46:17 +0000 (00:46 +0100)]
perl: Move 'pl*' to core.pm.

The guide says that 'quux-eval', which the perl implementation calls
'pl*', should be a core function.  I can't see any good reason why it
shouldn't be, so I've turned it into one.

4 years agoperl: De-FATALise warnings.
Ben Harris [Sat, 27 Jul 2019 23:23:28 +0000 (00:23 +0100)]
perl: De-FATALise warnings.

The documentation says, 'the use of "FATAL => 'all'" is discouraged', so
it better to leave them non-fatal.

4 years agoperl: Tidy up imports at the top of each file.
Ben Harris [Sat, 27 Jul 2019 23:19:13 +0000 (00:19 +0100)]
perl: Tidy up imports at the top of each file.

I kept not knowing where to add things, so I've roughly sorted them into
pragmas, then external modules, then internal modules.  This helps with
the situation that internal modules are named in lower case, which is
odd for Perl (but normal for mal).

4 years agoperl: Remove step 0.5.
Ben Harris [Sat, 27 Jul 2019 23:05:16 +0000 (00:05 +0100)]
perl: Remove step 0.5.

It seems to be just a less-complete version of step 0.

4 years agoperl: Simplify call to Mal::Env->new in 'catch*'.
Ben Harris [Sat, 27 Jul 2019 13:51:08 +0000 (14:51 +0100)]
perl: Simplify call to Mal::Env->new in 'catch*'.

Mal::Env->new doesn't need its array references to be blessed, so just
pass them plain.  This saves a bit of messing about with Mal::List->new.

4 years agoperl: Use autodie in 'slurp', getting us better error messages.
Ben Harris [Sat, 27 Jul 2019 12:08:45 +0000 (13:08 +0100)]
perl: Use autodie in 'slurp', getting us better error messages.

4 years agoperl: Propagate exceptions through 'pl*'.
Ben Harris [Sat, 27 Jul 2019 12:03:38 +0000 (13:03 +0100)]
perl: Propagate exceptions through 'pl*'.

4 years agoperl: Be more careful when investigating the type of an exception.
Ben Harris [Sat, 27 Jul 2019 11:49:45 +0000 (12:49 +0100)]
perl: Be more careful when investigating the type of an exception.

It's not safe to call "isa" on unblessed references, and not all
reference types are valid mal values.  Now only actual mal values get
treated as such and everything else gets printed as-is or converted to a
Mal::String.

4 years agoperl: When converting perl values to mal ones, convert undef to nil.
Ben Harris [Sat, 27 Jul 2019 11:40:04 +0000 (12:40 +0100)]
perl: When converting perl values to mal ones, convert undef to nil.

4 years agoperl: Introduce Mal::Type: a superclass for all the mal value classes.
Ben Harris [Sat, 27 Jul 2019 11:23:12 +0000 (12:23 +0100)]
perl: Introduce Mal::Type: a superclass for all the mal value classes.

This makes it simple to check if a perl object is one that can be passed
to mal code (e.g. in an exception handler).

4 years agoperl: Remove use of "autodie" in REPL.
Ben Harris [Sat, 27 Jul 2019 11:15:20 +0000 (12:15 +0100)]
perl: Remove use of "autodie" in REPL.

"autodie" has lexical scope and doesn't affect "print", so it's useless
using it in a scope that only contains a "print" and a call to EVAL.

4 years agoperl: Make a Mal::Scalar superclass for scalars.
Ben Harris [Sat, 27 Jul 2019 11:10:20 +0000 (12:10 +0100)]
perl: Make a Mal::Scalar superclass for scalars.

It contains a constructor that can be shared by all of them.

4 years agoperl: Rename all mal classes to begin with "Mal::".
Ben Harris [Sat, 27 Jul 2019 10:53:37 +0000 (11:53 +0100)]
perl: Rename all mal classes to begin with "Mal::".

Perl package names (and hence class names) are global, meaning that if
any module that we use loads a module called "Symbol", it will clash
with mal's Symbol class.  It turns out that something does this already,
which breaks inheritance from mal's Symbol class.  Since most of mal's
class names are very generic, it seems wise to rename all of them.

4 years agoperl: Remove now-unused HashMap::get method.
Ben Harris [Sat, 27 Jul 2019 00:20:19 +0000 (01:20 +0100)]
perl: Remove now-unused HashMap::get method.

4 years agoperl: Use '//' instead of '||' to provide defaults.
Ben Harris [Fri, 26 Jul 2019 23:34:43 +0000 (00:34 +0100)]
perl: Use '//' instead of '||' to provide defaults.

This avoids depending on the fact that all mal values are true.

4 years agoperl: Simpler handling of symbols in step 2.
Ben Harris [Fri, 26 Jul 2019 22:52:19 +0000 (23:52 +0100)]
perl: Simpler handling of symbols in step 2.

4 years agoperl: Use string interpolation on "not found" error message.
Ben Harris [Fri, 26 Jul 2019 22:51:30 +0000 (23:51 +0100)]
perl: Use string interpolation on "not found" error message.

4 years agoperl: Simplify code of eval_ast as applied to sequences and hash-maps.
Ben Harris [Fri, 26 Jul 2019 22:28:46 +0000 (23:28 +0100)]
perl: Simplify code of eval_ast as applied to sequences and hash-maps.

Specifically, the hash-map case now uses 'pairmap' to avoid the need for
a 'for' loop.  The code for sequences is now shared between lists and
vectors, since only the destination type differs.

4 years agoperl: Abolish _assoc_BANG.
Ben Harris [Fri, 26 Jul 2019 21:48:46 +0000 (22:48 +0100)]
perl: Abolish _assoc_BANG.

_hash_map and assoc both get simpler by not using it.

4 years agoperl: Fold some simple core functions into %core::ns.
Ben Harris [Fri, 26 Jul 2019 21:01:36 +0000 (22:01 +0100)]
perl: Fold some simple core functions into %core::ns.

4 years agoperl: Tidy up whitespace in table of core functions.
Ben Harris [Fri, 26 Jul 2019 20:35:52 +0000 (21:35 +0100)]
perl: Tidy up whitespace in table of core functions.

4 years agoperl: Fold _dissoc_BANG into dissoc and simplify.
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.

4 years agoperl: Use List::Util::pairs instead of "for (;;)" in 'let*' and 'assoc'.
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'.

4 years agobasic: args file that doesn't rely on return value.
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.

4 years agoMerge pull request #430 from bjh21/bjh21-perl
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)

4 years agoMerge branch 'master' into bjh21-unterminated-strings
Ben Harris [Thu, 25 Jul 2019 23:08:48 +0000 (00:08 +0100)]
Merge branch 'master' into bjh21-unterminated-strings

This should fix ocaml.

4 years agoperl: Clone functions before turning them into macros.
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).

4 years agoperl: Overload '@{}' and '%{}' on Nil.
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.

4 years agoperl: Take advantage of all mal values' being true to simplify code.
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.

4 years agoperl: Replace 'scalar(@x) > 0' with simply '@x'.
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.

4 years agoperl: Remove a completely useless use of 'scalar'.
Ben Harris [Thu, 25 Jul 2019 22:01:10 +0000 (23:01 +0100)]
perl: Remove a completely useless use of 'scalar'.

4 years agoperl: Don't use regexps in 'when' clauses to match fixed strings.
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.

4 years agoperl: Replace %core::core_ns with %core::ns.
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.

4 years agoperl: Turn $core_ns into %core_ns.
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.