Skip to content

Instantly share code, notes, and snippets.

View jeremytregunna's full-sized avatar

Jeremy Tregunna jeremytregunna

View GitHub Profile
ack = method x, y,
if x == 0 return y + 1.
if y == 0 return ack x - 1, 1.
ack x - 1, ack x, y - 1..
// Io
tak := method(x, y, z,
if(y < x,
tak(tak(x - 1, y, z), tak(y - 1, z, x), tak(z - 1, x, y))
,
z
)
)
// Other
- form_for :account, '/accounts', :id => 'loginform' do |f|
dl class="zend_form"
dt id="firstname-label"
== f.label :name, :caption => "First name:"
dd id="firstname-element"
== f.text_field :name
dt id="lastname-label"
== f.label :surname, :caption => "Last name:"
dd id="lastname-element"
@jeremytregunna
jeremytregunna / sarray.c
Created August 5, 2011 22:02
sparse array
/*******************************************************************
* Caribou Programming Language
* Copyright (C) 2010, Jeremy Tregunna, All Rights Reserved.
* Originally written by: David Chisnall
*
* This software project, which includes this module, is protected
* under Canadian copyright legislation, as well as international
* treaty. It may be used only as directed by the copyright holder.
* The copyright holder hereby consents to usage and distribution
* based on the terms and conditions of the MIT license, which may
(function text-view (frame)
((NSTextView alloc) initWithFrame: frame))
(function text-field (frame)
(((NSTextField alloc) initWithFrame: frame)
set: (bezeled:0 editable:0 alignment:NSCenterTextAlignment drawsBackground:0)))
(function alert-box (title message)
(let (alert (NSAlert new))
(let (t (text-view '(0 0 300 100)))
fib := n ->
0 to: 1 includes? n ifTrue: return n
fib: n - 1. + fib: n - 2.
fib := method: n, ->
0 to: 1 includes? n ifTrue: return n
fib: n - 1. + fib: n - 2.
Lexer := Object clone do(
inputString := Sequence clone
current ::= nil
next ::= nil
with := method(str, self clone setInputString(str))
setInputString := method(str,
inputString = str
self
Complex := Sequence clone do(
setItemType("float32")
setSize(2)
real := method(at(0))
imaginary := method(at(1))
setReal := method(a, atPut(0, a); self)
setImaginary := method(a, atPut(1, a); self)
with := method(r, i, self clone setReal(r) setImaginary(i))
abs := method((real * real + imaginary * imaginary) sqrt)
)
/* Converts any Io method (You'll have to wrap CFunctions in an Io method for those to work) to continuation passing style */
/* This is working code, not code someone posted asking for help. Feel free to use how you want, public domain. */
Object convertToCPS := method(str,
m := self getSlot(str)
blk := Block clone
blk setArgumentNames(getSlot("m") argumentNames append("__k"))
blk setMessage(Message clone fromString("__k call(self performWithArgList(\"#{str}\", call evalArgs append(__k)))" interpolate))
self setSlot("#{str}CPS" interpolate, blk setIsActivatable(true))
)