Giter Site home page Giter Site logo

stacky's Introduction

Stacky

Stacky was a postscript inspired stack language.

The project had a simple purpose: try to make a programming language and fail fast to learn from it.

Some relative success came along the way. The implementation is not optimized at all. I also changed directions numerous times. I stalled when I attempted to introduce types.

code samples

Comments

% comments start with a percent signe 

Multiline comments are buggy in the last implementation.

%( Multiple 
   line
   comments )%

Literals

  • Booleans
true
false
  • Strings:
"hello world!\n"
  • Raw Strings:
r"\n is not escaped here"
  • Integers:
1 2 
  • Floats:
1.2 3.14
  • Arrays: sequence delimited by parentheses
( 1 2 3 )
  • Dictionaries: sequence of pairs delimeted by squared brackets
stacky> [ 1 "hello" 2 "world" ]
[2i: "world", 1i: "hello"]
  • Functions: sequence of literals within curly braces
{ 5 + }

Anything else refers to a symbol defined in a global or local dictionary.

Symbols can be escaped so as to not be interpreted by prefixing them by a /. This can be used in conjonction with def to define variables.

/hello "hello" def

Function examples

  • A sum
/sum {
    0 swap { + } for-all
} def
  • A range function
/range { 
    () 3 swapn { 
        swap push 
    } for 
} def

1 1 10 range sum print-ln
  • Test a predicate holds for all the values within an array.
/all { 
    /proc   swap def 
    /array  swap def
    /status true def
    
    array { 
        proc true = not { 
            /status false def 
        } if 
    } for-all
    
    status
} def 

( 1 2 3 ) { 5 < } all
  • Test that one element of an array satisfies a given predicate.
/any { 
    /proc   swap def 
    /array  swap def
    
    array { 
        proc true = { 
            true 
            return
        } if 
    } for-all
} def 

( 1 2 3 ) { 5 < } any
  • The map function
/map {
    /proc   swap  def
    /source swap  def
    /target  ()   def 

    source { proc target push } for-all

    target
} def
  • The filter function
/filter {
    /proc   swap def
    /source swap def 
    /target  ()  def

    source {
        dup proc true =
        { target push } { drop } if-else
    } for-all
    
    target
} def

stacky's People

Contributors

remy-j-a-moueza avatar

Watchers

 avatar

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.