Last active
May 11, 2021 13:15
-
-
Save Alan-Liang/491bd0561481e6fdb2b981cb932fad5d to your computer and use it in GitHub Desktop.
An example of some strange language named Pipette and their equivalencies in JavaScript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TODO: this is obsolete | |
'use strict' | |
require('@pipette/polyfill') | |
;(async function() { | |
const start = 0 // const start = 0 | |
const count = _pt_channel(start) // let count = start | |
const plus = async function() { // fun plus() { | |
_pt_in1 = await count() // count |{ | |
await print(_pt_in1) // print <in | |
await count(_pt_in1 + 1) // count <in + 1 | |
// } | |
} // } | |
for(var _pt_in2 in await range(10)) { // range(10) >for { | |
plus() // plus() | |
} // } | |
_pt_deferGlobal(async function() { | |
await print(await count()) // defer print <|count | |
} | |
})() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const start = 0 | |
let count = start | |
fun plus() { | |
count |{ | |
print <in | |
count <in + 1 | |
} | |
} | |
range(10) >for { | |
plus& | |
} | |
defer print <|count |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
require('@pipette/polyfill') | |
;(async function() { | |
const _throw = async function() { // fun _throw() { | |
throw 'error' // err <'error' | |
return // return | |
} // } | |
const a = async function() { // fun a() { | |
try { await print(await _throw()) } catch(_pt_in1) { await _pt_handlePanic(_pt_in1, async function() { // _throw |print err|if { | |
await print(_pt_in1) // print <in | |
})} // } | |
await _throw() // throw | |
await print(1) // print <1 // not called | |
} // } | |
const b = async function() { // fun b() { | |
try { await a() } catch(_pt_in2) { _pt_handlePanic(_pt_in2); _pt_panic(_pt_in2) }// a err|panic | |
} // } | |
const c = _pt_defer(async function(_pt_deferId) { // fun c() { | |
_pt_deferId(0) | |
await b() // b | |
}, [ | |
async function() { | |
const _pt_in3 = _pt_recover(); if(_pt_in3) { // defer recover |if { | |
await print(_pt_in3) // print <in | |
} // } | |
} | |
]) // } | |
await c() // c | |
})() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun _throw() { | |
err <'error' | |
return | |
} | |
fun a() { | |
_throw |print err|if { | |
print <in | |
} | |
_throw | |
print <1 // not called | |
} | |
fun b() { | |
a err|panic | |
} | |
fun c() { | |
defer recover |if { | |
print <in | |
} | |
b | |
} | |
c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment