Skip to content

bk20x/calico

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Calico

A little scripting language with first class environments and the ability to call ruby methods directly

Very WIP, funnily enough I made this after telling myself I was going to make a bc clone in with operator precedence to learn the language


Time <- find-class('Time')

now  <- use Time in { now().inspect().reverse() * 3 }

Counter <- [] {
   x <- 0
   {
      inc <- [] {x := x + 1}
      dec <- [] {x := x - 1}
      get <- [] {x}
   }
}

counter <- Counter()

for _ in 0..5 {
    print(counter.inc())
}

List <- [*init] {
  {
    items <- init
    add <- [x]{
      items.push(x)
    }
    at <- [idx] {
      items.at(idx)
    }
    map <- [f] {
      result <- @[]
      for x in items {
        result.push(f(x))
      }
    }
    filter <- [f] {
      result <- @[]
      for x in items {
        if f(x) {
          result.push(x)
        }
        else {
          result
        }
      }
    }
  }
}

ys <- List(2, 4, 6, 8)

use ys in {
  add(5)
  add(10)
  add(15)
  items := map([x]{ x * x })
}

print(ys.items.inspect())

ip <- do {
  Http <- find-class('Net::HTTP')
  Http.get('ident.me', '/')
}

print(ip)


fun <- [] {
  print(myVar)
}

fun.closure := {
  myVar <- 'Hello World!'
}

fun()

map <- [xs f] {
  result <- @[]
  for x in xs {result.push(x -> f)} 
}

filter <- [xs f] {
  result <- @[]
  for x in xs {
    if f(x) {
      result.push(x)
    }
    else {
      result
    }
  }
}

methods <- Time.methods() -> map([method]{method.to_s()}) -> filter([name]{name.include?('class')})

About

Little scripting language made in Ruby!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages