Skip to content

Commit 4d05ebe

Browse files
committed
visual-lambda: update redame
1 parent e17e71e commit 4d05ebe

5 files changed

Lines changed: 39 additions & 11 deletions

File tree

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ and from https://bitbucket.org/bntr/visual-lambda too.
55

66
![logo](http://bntr.planet.ee/lambda/loop_.gif)
77

8-
Visual Lambda environment allows intuitive manipulation of lambda calculus expressions.
8+
The Visual Lambda environment enables intuitive manipulation of lambda calculus expressions.
99

1010
## Screenshot
1111

@@ -15,11 +15,12 @@ Visual Lambda environment allows intuitive manipulation of lambda calculus expre
1515
- [Basics](http://bntr.planet.ee/lambda/visual_lambda_bubble_notation.gif)
1616
- More detailed in this thesis [visual_lambda.pdf](http://bntr.planet.ee/lambda/work/visual_lambda.pdf)
1717

18-
## Examples
18+
## Reduction animation examples
1919
- ['MULT 3 2' evaluation](http://bntr.planet.ee/lambda/visual_lambda_MULT_3_2_=_6.gif)
2020
- ['((λgm.m(gg))(λgm.m(gg)))M' building and evaluation](http://bntr.planet.ee/lambda/lambda_F_anim.gif)
2121
- ['Y I' evaluation](http://bntr.planet.ee/lambda/Y_I.gif)
2222

23+
2324
## Dependencies
2425
- python 3
2526
- pygame 2.4.0
@@ -30,8 +31,12 @@ Visual Lambda environment allows intuitive manipulation of lambda calculus expre
3031
## Controls
3132
- [controls.txt](controls.txt)
3233

34+
## Predefined expression library
35+
- [library.txt](library.txt)
36+
37+
3338
## Related works
34-
- [Programming with Visual Expressions, Wayne Citrin](http://users.encs.concordia.ca/~haarslev/vl95www/html-papers/citrin/citrin.html)
35-
- [A Graphical Notation for the Lambda Calculus, Dave Keenan](http://dkeenan.com/Lambda/)
36-
- [Lambda Animator, Mike Thyer](http://thyer.name/lambda-animator/)
39+
- [Programming with Visual Expressions, Wayne Citrin](https://web.archive.org/web/20110524135539/users.encs.concordia.ca/~haarslev/vl95www/html-papers/citrin/citrin.html)
40+
- [A Graphical Notation for the Lambda Calculus, Dave Keenan](https://dkeenan.com/Lambda/)
3741
- [Alligator Eggs, Bret Victor](http://worrydream.com/AlligatorEggs/)
42+
- More in [prathyvsh's catalog](https://github.com/prathyvsh/lambda-calculus-visualizations)

localstorage.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
function addItem(expression) {
2626
setStorageValue("addItem", expression, "|");
2727
}
28+
function clearWorkspace() {
29+
setStorageValue("clearWorkspace", "1");
30+
}
2831
function saveWorkspace(workspaceName) {
2932
setStorageValue("saveWorkspace", workspaceName);
3033
}
@@ -33,6 +36,7 @@
3336
}
3437
function help() {
3538
console.log("addItem(expression) - add an item by expression, e.g. addItem('\\x. x x')");
39+
console.log("clearWorkspace() - clear the workspace");
3640
console.log("saveWorkspace(workspaceName) - save current workspace to localStorage, e.g. saveWorkspace('combinators3')");
3741
console.log("loadWorkspace(workspaceName) - load a workspace from localStorage, e.g. loadWorkspace('combinators3')");
3842
}

main.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ def __init__( self, caption ):
301301

302302

303303
async def run( self ):
304+
305+
sleepSec = 0.02
306+
if config.IS_WEB_PLATFORM:
307+
sleepSec = 0 # pygbag asked for 0
304308

305309
while True:
306310

@@ -309,7 +313,7 @@ async def run( self ):
309313
if e.type == pygame.QUIT:
310314
return
311315

312-
await asyncio.sleep(0)
316+
await asyncio.sleep(sleepSec)
313317

314318

315319

@@ -610,9 +614,10 @@ def saveView( self ):
610614
self.viewMatrixSaved = self.viewMatrix.copy()
611615
print("The View was saved")
612616
def restoreView( self ):
613-
self.viewMatrix = self.viewMatrixSaved
614-
self.invalidate()
615-
print("The View was restored")
617+
if self.viewMatrixSaved:
618+
self.viewMatrix = self.viewMatrixSaved
619+
self.invalidate()
620+
print("The View was restored")
616621

617622

618623
def updateSelectionStatus( self ):
@@ -817,6 +822,7 @@ def handleEvent( self, event ):
817822
if event.type == LOCALSTORAGE_TIMEREVENT:
818823
# Check if user has called a browser console command, e.g. addItem('\\x. x x')
819824
localstorage.handle_storage('addItem', self.onInputItem, "|")
825+
localstorage.handle_storage('clearWorkspace', self.onClearWorkspace)
820826
localstorage.handle_storage('saveWorkspace', self.onSaveWorkspaceName)
821827
localstorage.handle_storage('loadWorkspace', self.onLoadWorkspaceName)
822828

@@ -995,6 +1001,10 @@ def onSaveWorkspaceFileName( self, workspaceName ):
9951001

9961002
if config.IS_WEB_PLATFORM: # Save to/Load from localStorage
9971003

1004+
def onClearWorkspace( self, _ ):
1005+
if saving.load_from_file( self, "clear.xml" ):
1006+
self.invalidate()
1007+
9981008
def onSaveWorkspaceName( self, workspaceName ):
9991009
xmlData = saving.save( self, pretty = True )
10001010
if xmlData:

visual-lambda-2.0/build/web/index.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,17 +491,21 @@
491491
window.localStorage.setItem(key, value);
492492
}
493493

494-
function addtItem(expression) {
494+
function addItem(expression) {
495495
setStorageValue("addItem", expression, "|");
496496
}
497+
function clearWorkspace() {
498+
setStorageValue("clearWorkspace", "1");
499+
}
497500
function saveWorkspace(workspaceName) {
498501
setStorageValue("saveWorkspace", workspaceName);
499502
}
500503
function loadWorkspace(workspaceName) {
501504
setStorageValue("loadWorkspace", workspaceName);
502505
}
503506
function help() {
504-
console.log("inputItem(expression) - add an item by expression, e.g. inputItem('\\x. x x')");
507+
console.log("addItem(expression) - add an item by expression, e.g. addItem('\\x. x x')");
508+
console.log("clearWorkspace() - clear the workspace");
505509
console.log("saveWorkspace(workspaceName) - save current workspace to localStorage, e.g. saveWorkspace('combinators3')");
506510
console.log("loadWorkspace(workspaceName) - load a workspace from localStorage, e.g. loadWorkspace('combinators3')");
507511
}

workspaces/library_demo.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666

6767
<item pos="-6,-40" figure="(\x. x x) (\x. x x)" /> <item pos="0,-40" text="LOOP = (\x. x x) (\x. x x)" />
6868

69+
70+
71+
<item pos="0,-52" text="FACTORIAL" origin="1" />
72+
73+
<item pos="-8,-12" figure="FACT" /> <item pos="3,-6" text="FACT = Y (\f n. (ISZERO n) 1 (MULT (f (PRED n)) n))" />
6974

7075
</items>
7176
</workspace>

0 commit comments

Comments
 (0)