From 908d8f01d5e964971ad76909c0ec31468ee93d2d Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 16 Apr 2019 00:12:37 +0200 Subject: Play around with a vector type Using _vectors_ as fundamental datatype could make for a really neat experience. Imagine e.g.: * fundamental arithmetic operations that apply to both vectors and scalars * implicit component-wise or vector-wise operations * scalar values as 1D vectors * higher order functions to manipulate those vectors * `map` function that applies a (quoted?) word to all vector elements and returns the result * efficient parallel operations * a rich library of vector manipulation functions * or even: matrices as a fundamental datatype? * problem: probably harder to conveniently enter via a 1-D repl * sound more and more like a RPN version of APL… Back to reality, here is what this prototype actually adds: * new `DList!int` based datatype alongside the existing int, string and bool types * basic support for printing such values in a readable fashion * new fundamental `:` word that constructs a vector of two elements * `1 2 :` yields `[1, 2]` * adapted `+` and `*` to support component-wise operations * `1 2 : 3 +` yields `[4, 5]` --- source/state/variable.d | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source/state/variable.d') diff --git a/source/state/variable.d b/source/state/variable.d index f77e207..978a2fd 100644 --- a/source/state/variable.d +++ b/source/state/variable.d @@ -16,7 +16,8 @@ bool handle(Token token) { return token.visit!( (int ) => false, (bool ) => false, - (string word) => handle(word) + (string word) => handle(word), + (DList!int ) => false ); } -- cgit v1.2.3