Skip to content

Instantly share code, notes, and snippets.

View nmorse's full-sized avatar
🔮

Nate Morse nmorse

🔮
View GitHub Profile
# 4474
seq = [[None,None,None,[0,-1],[0,0]],[1,true,2,[0,1],[2,0]],[3,false,2,[0,-1],[8,0]],[8,false,3,[1,0],[0,8]]]
@nmorse
nmorse / ever-increasing.pounce
Created December 31, 2022 13:41
Determine if there are ever increasing values in a list
[2 4 5 6 7] [0 true] [[[acc p] d] [[] d push acc d < p && push ] pounce] reduce uncons uncons rolldown drop drop
[6 3 8 4 5 7 2 9 1]
[1 0] # accumulator is a pair [acc index] the index is used to either multiply or add
[swap uncons uncons drop [acc i] [acc [i 2 % 0 ==] [*] [+] ifte 1 i +] pounce [] cons cons]
reduce
# current limiting resistor calculator
# run at https://pounce-lang-show-case.netlify.app/
[.05][i]compose # forward Amps from LED specifications
[3][Vf]compose # forward voltage from LED specifications
[6][Vs]compose #supply voltage
Vs Vf - i / Ohms
@nmorse
nmorse / serpinski-pi.pounce
Created September 8, 2022 13:01
from Matt Parker
1 [] [[2 + dup] dip cons] 993 times [drop] dip
4 [dup * dup 1 - swap / *]
reduce
@nmorse
nmorse / some-stack-play.pounce
Created August 17, 2022 15:34
can this stuff be dependently typed and proven not to violate stack norms
2 4 a d f g 7 depth [[[drop] dip] dip] swap 2 - times # g 7
2 4 a d f g 7 depth [[drop] dip2] swap 2 - times # same
2 4 a d f g 7 depth [drop] swap 2 - times # 2 4
@nmorse
nmorse / tixy-like-exp.pounce
Created February 26, 2022 16:21
Exploring the use of a crouch word in Pounce. Like the word `pounce` but without `play`
# tri (N N N N N -- [(N N -- N)])
[tri] [[base peak offset slew n] [[i t] [t slew + n % i offset + base + +] pounce] crouch] compose
[[5 4 3 .4 20 tri] [8 3 1 -.2 20 tri]]
[play] map
[animationFrame] [play] subscribe
@nmorse
nmorse / repeat.pounce
Created August 11, 2021 03:33
repeat using pounce
0 1 [dup2 +] 8 repeat
[[p t][t 0 > [p play p t 1 - repeat] [] if-else ] pounce] [repeat] compose
@nmorse
nmorse / Church-encoding.pounce
Last active July 4, 2021 02:31
In which some of the Church encodings of Boolean logic are converted to Pounce-lang (after reading github.com/glebec/lambda-talk)
# Church encodings for boolean logic.
# `T` is for true, any other word is false (e.g. `F` )
# Evaluation of Church encoded logic (in pounce) will be composed as '^'
## if top of the stack is `T` then take the first (i.e. drop), else keep the second (i.e. swap drop)
[T == [drop][swap drop] if-else] [^] compose
# 'AND' in lambda calculus is \pq.pqp. Translated to post-fix `[p q] [p q q ^] pounce`
## or more simply `dup ^`
[dup ^] [and] compose
@nmorse
nmorse / code.py
Last active February 15, 2021 00:10
Simulated interrupt handler to test a rotary position algorithm (orig v1 from )
"""
Simulated interrupt handlers to test rotary position algorithms
features changing handles by entering (1 <enter> or 2 <enter>) into the console.
Todo: add more handler algorithms
"""
import board
from digitalio import DigitalInOut, Direction, Pull
import supervisor
# setup pins (a and b) for encoder