Skip to content

Commit

Permalink
Merge pull request #124 from aya-lang/alt-dict-syntax
Browse files Browse the repository at this point in the history
Change dict syntax from `{, ...}` to `:{...}`
  • Loading branch information
nick-paul authored Dec 30, 2024
2 parents 9912b73 + ec73a33 commit 99875fc
Show file tree
Hide file tree
Showing 126 changed files with 999 additions and 905 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Use aya's `turtle` and `color` modules to draw a pattern
import ::turtle
import ::color
{,
:{
400:width;
400:height;
color.colors.darkblue :bg_color;
Expand Down Expand Up @@ -225,7 +225,7 @@ import ::plot
import ::stats
"Downloading file..." :P
{,
:{
"https://raw.githubusercontent.com/vincentarelbundock/Rdatasets/master/csv/datasets/LakeHuron.csv":filename
1:csvindex
}
Expand All @@ -238,8 +238,8 @@ df.["value"] :y;
x y stats.regression :r;
plot.plot! :plt;
x y {, "Water Level":label} plt.plot
x {r} {, "Trend":label} plt.plot
x y :{ "Water Level":label} plt.plot
x {r} :{ "Trend":label} plt.plot
"Water Level of Lake Huron" plt.:title;
[575 583] plt.y.:lim;
Expand Down
2 changes: 1 addition & 1 deletion ayarc.aya
Original file line number Diff line number Diff line change
@@ -1 +1 @@
:{sys.ad} "base/__aya__.aya" + :F
:(sys.ad) "base/__aya__.aya" + :F
46 changes: 23 additions & 23 deletions base/__aya__.aya
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
.# NOTE: 12 letter variables ending in the letter 'z' are reserved for use in
.# standard library. Such variables are used below.

{:{sys.ad} "test/test.aya" + :F}:tt;
{:(sys.ad) "test/test.aya" + :F}:tt;

.# Global __aya__ table
{,
:{

{,}:interpreter;
:{}:interpreter;

.# If set to 1, all breakpoints will be ignored
.#? __aya__.ignore_breakpoints\n if true, skip all breakpoints
0 :ignore_breakpoints;

}:__aya__;

{,
{,
:{
:{
::__nil :__type__;
"nil" :__str__;
"nil" :__repr__'
Expand All @@ -41,7 +41,7 @@
.#? bp\n set a breakpoint
{ : __aya__^,
__aya__.ignore_breakpoints ! {
:{debug.pause}
:(debug.pause)
} ?
}:bp;

Expand All @@ -66,7 +66,7 @@
.# -------

{name,
[:{sys.ad} :9s "examples" :9s name ".aya"] W :F
[:(sys.ad) :9s "examples" :9s name ".aya"] W :F
}:example;


Expand All @@ -91,9 +91,9 @@
}
)

aya> f {,} ::foo {"a"}
aya> f :{} ::foo {"a"}
with_mod!
[ {"a"} ::foo {,} ]
[ {"a"} ::foo :{} ]

aya> f ::foo {"a"}
no mod!
Expand All @@ -109,7 +109,7 @@
_no_mod:no_mod;

.# Store functions on stack so they can be retrieved later
{,
:{
no_mod.` :no_mod
with_mod.` :with_mod
}
Expand All @@ -119,8 +119,8 @@
.# aya> {mod name block, mod ::_fn =! {;} ? [mod name block.`]} :f

.# Jump ahead 3 items
.# aya> (```(\:&:T ::sym=! {\`}{\}.? f) ::_fn) {,} ::foo {+}
.# [ {,} ::foo {+} ]
.# aya> (```(\:&:T ::sym=! {\`}{\}.? f) ::_fn) :{} ::foo {+}
.# [ :{} ::foo {+} ]

.# Jump ahead 2 items
.# aya> (```(\:&:T ::sym=! {\`}{\}.? f) ::_fn) ::foo {+}
Expand Down Expand Up @@ -156,7 +156,7 @@
}

.# Use constant substitution until var^ syntax is introduced
{, no_mod.`:_no_mod with_mod.`:_with_mod} .+
:{ no_mod.`:_no_mod with_mod.`:_with_mod} .+

} __aya__.:opt_mod;

Expand All @@ -178,7 +178,7 @@

Define a function in a module scope:

aya> {,}:math;
aya> :{}:math;
aya> def math::sq {2^}
aya> 5 math.sq
25
Expand All @@ -194,7 +194,7 @@

Define a function in a submodule:

aya> {, {,}:stats; }:math;
aya> :{ :{}:stats; }:math;
aya> def (math.stats)::mean {.E\W\/}
aya> [1 2 3 4] math.stats.mean
2.5
Expand All @@ -218,9 +218,9 @@
.#
.# `objcet`: Base object for class and struct
.#
{,
:{
{meta : instance,
{,
:{
meta :__meta__;
1 :__pushself__;
} :instance;
Expand Down Expand Up @@ -250,7 +250,7 @@
.#

{type::sym super,
{,
:{
super:__meta__;
type:__type__;
.# copy new from super directly
Expand Down Expand Up @@ -297,7 +297,7 @@ __aya__.extend.` :extend;
num_members :A
.# and assign them to self
members {self :D} .&;
} {,
} :{
members__ E :num_members;
members__ :members;
} .+ cls__.:__init__;
Expand All @@ -311,7 +311,7 @@ __aya__.extend.` :extend;
" ) " +
name +
"!"+
} {,
} :{
type__ :C :name;
members__ :members;
} .+ cls__.:__str__;
Expand All @@ -332,14 +332,14 @@ __aya__.extend.` :extend;

.#? module sym\n declare a new module
{name::sym,
{,
:{
name :__modname__;

{meta,
"Cannot create new instance of module $(meta.__modname__:C)" .D
} :__new__;

{,
:{
::module :__type__;
"(module $name)":__repr__;
}:__meta__;
Expand Down Expand Up @@ -448,5 +448,5 @@ __aya__.extend.` :extend;

] :# {f,
.# "Loading base/$f..." :P
load ([:{sys.ad} :9s "base/$f"]W)
load ([:(sys.ad) :9s "base/$f"]W)
};
20 changes: 2 additions & 18 deletions base/block.aya
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{,
:{

.# Functional Operations
.########################
Expand Down Expand Up @@ -60,7 +60,7 @@
.}
{(1 hold)({:d__,
.# Create a dictionary of all values given by the list
{,}:d__;
:{}:d__;
:#{$~\d__:D;};
.# Substitute the values from the dictionary into the block
d__ .+
Expand All @@ -72,22 +72,6 @@
.# Utility Functions
.#####################


.# ::list _capture_vars\n given a list of symbols, return a dict with each symbol and it's assignment
.{ Example:
aya> {1 +}:a 2:b
{1 +} 2
aya> [::a ::b].capture_vars
{,
{1 +}:a;
2:b;
}
aya> [::a ::b ::c].capture_vars
ERROR: Variable c not found
.}
{ {1, :# {$~\:=} } }:_capture_vars;


.#? ::block .op\n return the block (allows use of (::sym or ::block) .op without type checking
{}:op;

Expand Down
2 changes: 1 addition & 1 deletion base/char.aya
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

.# Metatable definition for the built-in `char` type

{,
:{
.#? C.islower\n tests if a character is lowercase
{$ 'a :> \ 'z :< &}:islower;

Expand Down
14 changes: 7 additions & 7 deletions base/importlib.aya
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ def importlib::_log_debug {:importlib^,
importlib._debug {"importlib: " \+ :P} {;} .?
}

def importlib::aya_dir :{sys.ad}
def importlib::aya_dir :(sys.ad)

.# Dictionary of files which have been imported
def importlib::imported {,}
def importlib::imported :{}

def importlib::path [
importlib.aya_dir "std" :9s + + .# <aya>/base
Expand All @@ -18,7 +18,7 @@ def importlib::path [
.# Return the path with the current directory at the bottom
def importlib::get_path { : importlib^ ,
importlib.path
:{sys.wd}
:(sys.wd)
J
}

Expand All @@ -34,7 +34,7 @@ def importlib::load_file {filename : importlib^,
{ .# try
"Attempting to open file $filename..." importlib._log_debug
.# Load the file into a dict scope
{,
:{
.# If __main__ exists and is 0, `main` will discard its block
.# Otherwise it will execute it
0:__main__;
Expand Down Expand Up @@ -138,7 +138,7 @@ def importlib::from_file {filepath : importlib^ all_possible mod,

importlib.get_path :# { filepath + } :~ :all_possible
.# Get only files that exist
{ :{sys.file_exists} } I
{ :(sys.file_exists) } I
.# If the lists is empty, throw an error
.E 0 = {"Import Error: Unable to find any of the following files: $all_possible" .D} ?

Expand Down Expand Up @@ -216,7 +216,7 @@ def importlib::export {vars : importlib^,
def importlib::from {mod_sym import_vars : meta_mod importlib^,
"$mod_sym $import_vars importlib.from" importlib._log_debug
"from: Capturing all imported vars..." importlib._log_debug
{,
:{
mod_sym importlib.import
}:meta_mod;

Expand Down Expand Up @@ -245,7 +245,7 @@ importlib __aya__.:importlib;
.# If provided a 0 (for example from `from` keyword), do nothing
{(1 hold)(:& 0= {;} {__aya__.importlib.import} .?)}:import;

{: importlib^ , {,} importlib.:imported; } :reimport;
{: importlib^ , :{} importlib.:imported; } :reimport;

{(1 hold)(__aya__.importlib.export)}:export;
{1:__export__;} :exportall;
Expand Down
4 changes: 2 additions & 2 deletions base/list.aya
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

.# Metatable definition for the built-in `list` type

{,
:{
.# Querying
.###############

Expand Down Expand Up @@ -152,7 +152,7 @@

.#? ::list.dict_flatten\n given a list of dicts, flatten the into a single dict
{
{,}\J{.+}%
:{}\J{.+}%
}:dict_flatten;


Expand Down
2 changes: 1 addition & 1 deletion base/num.aya
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

.# Metatable definition for the built-in `num` type

{,
:{

.#? ::num .digits\n convert a number into a list of digits
{
Expand Down
2 changes: 1 addition & 1 deletion base/str.aya
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.# string.aya
.# Defines functions for working with strings and regular expressions

{,
:{
.# Import list variables
[].M W

Expand Down
6 changes: 3 additions & 3 deletions base/sym.aya
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

.# Metatable definition for the built-in `sym` type

{,
:{
.{? ::sym .op

Return a block containing the operator
Expand All @@ -24,7 +24,7 @@
}:op;

.# Get a dict of all operator/symbol pairs
{,
:{
"overloadable" M? :# {
.# Get <name> <op> as strings
:& "overloadable:.*$" & .[0] " " S .[-1] \ " " S .[0]
Expand Down Expand Up @@ -54,7 +54,7 @@
::__radd__
.}

{,
:{
.# Get the overload list for all ops
::ops Ma :#{.overload}
.# Get all ops with non-zero length overloads
Expand Down
2 changes: 1 addition & 1 deletion base/test.aya
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.# test.aya
.# Defines an interface for testing aya code

{, } :test;
:{ } :test;

.# New simpler test function
{blk,
Expand Down
6 changes: 3 additions & 3 deletions examples/ayarc_eclipse.aya
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
.# cp examples/ayarc_eclipse.aya target/classes/ayarc.aya

.# The current working directory, split on path separator
:{sys.wd} '/ S
:(sys.wd) '/ S
.# Pop 2 dirs
{B ;} 2 %
.# Re-assemble the path
#"/"+ W
.# Set as current dir and aya dir
$ :{sys.cd} :{sys.set_ad}
$ :(sys.cd) :(sys.set_ad)

.# Load ayarc from the normal place
:{sys.wd} "ayarc.aya" + :F
:(sys.wd) "ayarc.aya" + :F
Loading

0 comments on commit 99875fc

Please sign in to comment.