Skip to content

Instantly share code, notes, and snippets.

View hashmal's full-sized avatar

Jérémy Pinat hashmal

View GitHub Profile
@hashmal
hashmal / try.shk
Last active December 16, 2015 06:29
-- try/rescue example
[] -- This list will be used as a data-stack by the `try' operation.
(try) [ derp ] -- `derp' is undefined
(rescue) [ "Error happened. Recovering." puts ]
"Recovered from error." puts
-- When run, it displays the following:
@hashmal
hashmal / try.md
Last active December 16, 2015 05:59

Proposal for "try blocks"

To fail gracefully, an operation needs to manipulate a different stack in order to be able to recover from an error (if an error occurs, the stack is in an undetermined state).

A try block can terminate in two ways:

  • The computation succeeded. In this case, its stack contents

In concatenative languages, any subexpression can be replaced with a name that represents the same subexpression.

Reserving operations in Shirka remove this property:

42 -> x   x   <- x      -- works

42 -> x [ x   <- x ] !  -- cannot undefine x

1 -> x 2 -> x <- x -- result is 2

@hashmal
hashmal / name-conv.md
Created April 13, 2013 19:41
Random thoughts about naming conventions in Shirka

Since Shirka is a tacit programming language, and the order of "arguments" is uncomon, it can be difficult to reason about what input operations need. In the following example:

while

It is quite natural to think the operation uses two objects from the stack: a value to check and something to do. However it is not clear in what order both objects must be on the stack.

@hashmal
hashmal / tpk_obfuscated.shk
Created April 12, 2013 07:32
[Shirka] Trabb Pardo-Knuth algorithm, simple layout obfuscation.
-- Trabb Pardo-Knuth algorithm, simple layout obfuscation.
(=> >>) [ -> x x <- x ] (=> <<) [ -> x ] (=> ><) [ -> x -> y <- x <- y ] (=>
puts) [ print '\n print ] (=> if) [ uncons -> iftrue uncons -> iffalse << ->
cond cond iftrue !? cond not iffalse !? ] (=> while) [ => cond => op [ cond [
op tail ] !? ] => tail tail ] (=> times) [ >< => op2 ([>> 0 >] while) [ 1 - ->
count op2 <- count ] << ] (=> each) [ => op-each length -> n (n times) [
uncons op-each ] << ] (=> list/reverse) [ "" >< ([length 0 = not] while) [ ->
src -> dest <- src uncons -> el -> src <- dest <- el cons <- src ] << ] (=>
gets) [ "" TRUE ([] while) [ getc >> '\n = not (if) [ [ cons TRUE ] [ cons
list/reverse FALSE ] ] ] ] (=> get-value) [ gets $parse length 1 = (if) [ [
@hashmal
hashmal / shirkagl.shk
Last active December 15, 2015 23:19
What OpenGL in Shirka could look like...
-- assuming the following operations are defined:
--
-- with -- require a module
-- case -- branching operation
-- ABORT -- terminate program
-- the `while' operation is normally already defined. The following
-- definition is here to show how adding new constructs to Shirka is done.
(=> while)
[ => condition
@hashmal
hashmal / shirka_draft.mkd
Last active July 3, 2020 14:03
Design of the Shirka programming language.

Shirka

Automatic garbage collection has made possible the implementation of many flexible, high-level languages in which memory management can simply be ignored most of the time. Unfortunately, garbage collectors have some properties that make their use in several fields (namely real-time applications) unpractical or even impossible:

  • Program execution is suspended during garbage collection cycles ("GC
@hashmal
hashmal / protocol.c
Created February 22, 2013 05:18
Not necessarily a good idea: "protocols" in plain old C.
#include <stdio.h>
#include <stdlib.h>
typedef void *any;
#define protocol(n) struct n
#define end(_)
// DECLARING THE SHOW PROTOCOL ///////////////////////////////////////////////
@hashmal
hashmal / gist:4190663
Created December 2, 2012 19:48 — forked from javan/gist:1168475
Fix iPhone home button
Found this tip in comment here: http://www.tipb.com/2011/01/04/tipb-bug-home-button-working-iphone/
1.) Open any application
2.) Press and hold the power button until the slide to shutdown swipe bar appears.
3.) Release Power button
4.) Press and hold Home button Lightly
until screen returns to icon screen
@hashmal
hashmal / demo.mz
Created December 1, 2012 18:44
Maize Demo
program main -> X is
0x08 fibonacci
end
-- Renvoie (R) le Nieme element de la suite de fibonacci.
-- PRECONDITION: N >= 0
program N fibonacci -> R is
take N 0x00 0x01 restore N