Coder Social home page Coder Social logo

wul's People

Watchers

 avatar  avatar

wul's Issues

Basic dictionary, associated array support

  • dict creates a MapTable using any value as a key.
  • table creates a MapTable using only identifiers as a key.

Example

(let me
  (dict ('name' 'szensk' 'age' 26))
)
(print (at me 'age')); prints 26

(let them
  (object (name 'arthur' age 21))
)
(print (at them age)); prints 21
  • dict function
  • at aka @ magic function
  • table magic function
  • set magic function

Factorial 14 overflows

Somehow the result is negative. I suspect implicitly converting to int in the * function.

Metatype support

  • All IValue types must use meta methods (NetFunctions, probably)
  • All predefined functions must invoke the metamethod specified by the left hand side's metatype
  • Add metamethods for bit operations
  • Add missing AsString metamethods
  • Set metamethod on type
  • Clone metatype of type
  • Set metatype on value

Recursive code not terminating

Test case

(def inc (a) (if (empty? a) (then ()) (else (concat (+ (first a) 1) (inc (rem a))))))
(inc (1 2))

Results

Stack overflow

Expected

(2 3)

Add a tree-walking interpreter

  • Add information to interpret the abstract syntax tree.
  • Add a tree walker
  • Add magic functions that prevent evaluation of arguments
  • Add def function
  • Equality
  • If Then Else
  • Recursive functions

Unpack macro

Motivation

Sometimes I have to apply a scalar function to a list, e.g. (+ (2 3 4)). Two options: (+ (unpack (2 3 4)) or (reduce + (2 3 4)). While reduce works in this case, it's less flexible in general.

Implementation

Unpack takes a list and returns multiple syntax nodes. Macro would be the easiest way to do this.

Variable arguments

  • Allow ... as an identifier
  • Place all remaining unbound arguments in a list named ...

Basic range support

  • Inclusive [a,b]
  • Default increment of -1 if a > b, 0 if a = b, 1 if a < b
  • Parse ranges
  • Range value type
  • First should yield
    • E.g. (first [0 5]) yields 0.
  • Rem should construct a new range value
    • E.g. (rem [0 5]) yields [1 5].
  • [1 3 by 1] should yield (1 2 3)
  • [1 3] should yield (1 2 3)
  • [4 0] should yield (4 3 2 1 0)
  • [4 0 by -2] should yield (4 2 0)
  • Ranges as index functions.
    • E.g. ([4 0 by -2] (1 2 3 4 5)) should yield (5 3 1).
    • E.g. ([0] (1 2 3)) should yield 1.

Add magical functions

  • Define alias def
  • Define Magic alias def!
  • Evaluate alias eval
  • LessThan alias <
  • Add alias +
  • If alias if
  • Then alias then
  • Else alias else

Invoke simple .NET methods

  • Convert IValue to .NET object
    • Number -> double
    • UString -> string
    • ListTable -> object[]
    • MapTable ->Dictionary
    • Bool -> bool
    • Function -> Func<...>
  • Convert .NET object to IValue
    • string -> UString
    • double -> Number
    • int -> Number
    • bool -> Bool
    • array -> ListTable
    • IEnumerable -> ListTable
    • Dictionary -> MapTable
  • :: method to invoke .NET methods

Add metamethods to all Values

Arithmetic

  • +,-
  • *,/,%,//
  • ** (power)

Bit

  • ~
  • <<, >>

Logical

  • not, and, or, xor (aka !, &, |, ^)
  • =,<, <=, >, >= (via cmp?)

List/String/Range

  • first
  • rem
  • len
  • empty?
  • push/pop
  • concat aka ..
  • at

Other

  • invoke

Magic function defined scope

Functions maintain their definition scope. Magic functions need their scope of execution (to define values within) and their scope of definition (to access up values).

Example

(def print-a 
  (let a 5 
    (@defn print-a () (print (eval a)))
  )
)
(print-a) ; prints nil
(def a 7)
(print-a) ; prints 7

Expected
Should print 5. Behavior should parallel regular functions.

Quote operator

Function quote prevents the evaluation of a syntax node. So (quote ()) returns a ListNode.

Short circuit and/or

  • Short circuit and
  • Short circuit or
  • (and 2 1) should return 1
  • (and 1 nil) should return nil
  • (and nil 1) should return nil
  • (or nil 1) should return 1
  • (or 1 2) should return 1

Comments in lists breaks parsing

Example

(defn add (a b c)
  (+ a b) ; this adds the first two arguments
)

Expected
It should produce a list node.

Result
It produces nil.

Macros

Macro

  • Replace magic function with macro.
  • Close scope exactly the same as normal functions.
  • Evaluate macro body w.r.t. closed scope
  • May return value (e.g. 8) or syntax node (e.g. (quote 8)).
  • If result is syntax node, eval once.
  • return result.
  • Rename @defn
  • Rename MagicFunction
  • Rename @invoke aka InvokeMagic meta-method
  • Update examples

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.