You are not logged in or registered. Please login or register to use the full functionality of this board...
SIGN IN Join Our Community For FREE


Funkey
06-27-2017, 01:14 AM
Post: #1
 (Print Post)
Funkey
Code and docs are attached. From the documentation:
Quote:
FUNKEY is an imperative, stack-based interpreted programming language with a REPL interface, reminiscent of Forth. Instead of typing though, commands are entered by playing the appropriate musical notes, which are read via the microphone. Briefly, the interpreter is capable of handling integers, basic maths operations, nested conditional (IF) and iterator (FOR) blocks, recursive user-defined functions and variables (though the stack architecture means interesting programs can be written without variables).
Why input programs in such a strange way? As we know, keyboards are complicated things and can scare away people who are not coders. This programming language brings it to a wider audience; now anyone with a suitable instrument (piano, recorder, flute, xylophone, violin to name a few) can program a computer. This is truly a revolution in computing.

See the attached funkey.txt for installation details, language specification and some examples. funkey.py is the interpreter itself. Requires Python 3, and a few libraries. Only tested on Linux.

Both files meet the length requirements:
Quote:
$ wc funkey.py funkey.txt
   94   370  5089 funkey.py
  121  1282  7419 funkey.txt


Have fun!


Attached File(s)
.py  funkey.py (Size: 4.97 KB / Downloads: 13)
.txt  funkey.txt (Size: 7.25 KB / Downloads: 28)
Find all posts by this user
Like Post
The following 1 user Likes flukiluke's post:
bplus
06-27-2017, 12:25 PM (This post was last modified: 06-27-2017 12:28 PM by bplus.)
Post: #2
 (Print Post)
RE: Funkey
bplus shopping list:
 + Musical instrument, + microphone... + Linux ??? (I have conspiracy theories about people who use Linux but no worries, they are in same shape as people who use BASIC. ;D  )
0 I think Python is cross platform since I have both versions on Windows 10, so maybe - Linux is NOT necessary. Wink

Imagine coding by playing an instrument! Cool! but would any catchy melodies actually occur? A Swan Lake or an 1812 Overature (Overture for spelling fans) or Hey Jude?

Now this gives me an idea! I started something with a mouse and drawing /sounding musical notes on screen and recording sights and sounds in data file.
Just bypassed need for - microphone or musical instrument , use mouse!
Wait, probably don't need Python either...  Big Grin

B += _
Find all posts by this user
Like Post
06-28-2017, 03:58 PM (This post was last modified: 06-28-2017 03:59 PM by bplus.)
Post: #3
 (Print Post)
RE: Funkey
While reviewing FunKey code, I encounter this line that looks very interesting:


Code Snippet: [Select]
exec(['s.push(s.pop2())','s.push(int(s.program[s.ip+1]));s.ip+=1','s.push(s.stack[-2])','print(s.pop())','s.push(s.stack[-1])','','if self.pop():\n s.control.append((-1,0,0))\nelse:\n n=1\n while s.program[s.ip]!=7 or n:\n  s.ip+=1\n  if s.program[s.ip]==6:n+=1\n  if s.program[s.ip]==7:n-=1','','step=s.pop();start=s.pop();end=s.pop()\nif start > end:\n n=1\n while s.program[s.ip]!=9 or n:\n  s.ip+=1\n  if s.program[s.ip]==8:n+=1\n  if s.program[s.ip]==9:n-=1\nelse.control.append((s.ip,step,end));s.cts.append(start)','s.cts[-1]+=s.control[-1][1]\nif s.cts[-1]<=s.control[-1][2].ip=s.control[-1][0]\nelse.cts.pop();s.control.pop()','s.push(s.cts[-1])','','s.push(s.pop()*s.pop())','s.push(s.pop2()//s.pop())','name = s.program[s.ip+1];s.ip+=2;function=[]\nwhile s.program[s.ip]!=5:\n function.append(s.program[s.ip]);s.ip+=1\ns.functions[name]=function','call=Machine(stack=s.stack,variables=s.variables,functions=s.functions);call.feed(s.functions[s.program[s.ip+1]]);call.run();s.ip+=1','s.push(s.pop()+s.pop())','s.push(s.pop2()-s.pop())','s.variables[s.program[s.ip+1]]=s.pop();s.ip+=1','s.push(s.variables[s.program[s.ip+1]]);s.ip+=1','','s.push(int(s.pop2()<s.pop()))','s.push(int(s.pop2()>s.pop()))','s.push(int(self.pop()==self.pop()))','s.push(s.pop2()%s.pop())','s.push(s.cts[-2])'][s.program[s.ip]])


Is anyone around who can describe Python's EXEC (or is this coming from an import item)?

B += _
Find all posts by this user
Like Post
06-28-2017, 10:24 PM (This post was last modified: 06-28-2017 10:26 PM by flukiluke.)
Post: #4
 (Print Post)
RE: Funkey
This is largely a trick to keep the program under 100 lines.

As you can see, we have a large list of strings, and then take the string at position s.program[s.ip]. s.ip is an instruction pointer and s.program is all the commands to br executed, so s.program[s.ip] is the current command (as a number). Each string in the list corresponds to a command. exec() takes a string containing Python code and executes it as if it were written in the file; \n is used to embed newlines.

It also looks nice, because all the logic of the virtual machine that executes the code is bundled up into one list.
Find all posts by this user
Like Post



Forum Jump:


User(s) browsing this thread: 1 Guest(s)




QB64 Member Project - Dreamy Clock
QB64 Member Project - Kings Valley verion one
QB64 Member Project - OpenGL Triangles
QB64 Member Project - Quarto
QB64 Member Project - Kings Court
QB64 Member Project - Input
QB64 Member Project - Martin Fractals version four
QB64 Member Project - Martin Fractals version two
QB64 Member Project - Line Thickness
QB64 Member Project - Touche
QB64 Member Project - Rubix's Magic
QB64 Member Project - ARB Checkers
QB64 Member Project - Othello
QB64 Member Project - Full Color LED Sign
QB64 Member Project - Algeria Weather
QB64 Member Project - Score 4
QB64 Member Project - Sabotage
QB64 Member Project - Pivet version one
QB64 Member Project - Bowditch curve
QB64 Member Project - Pivot version two
QB64 Member Project - STxAxTIC 3D World
QB64 Member Project - Basic Dithering
QB64 Member Project - Point Blank
QB64 Member Project - Connect Four
QB64 Member Project - Isolation
QB64 Member Project - Domain
QB64 Member Project - MAPTRIANGLE
QB64 Member Project - Exit
QB64 Member Project - Qubic
QB64 Member Project - Kings Vallery version two
QB64 Member Project - Inside Moves
QB64 Member Project - Swirl
QB64 Member Project - Amazon
QB64 Member Project - RGB Color Wheel
QB64 Member Project - Rotating Background
QB64 Member Project - Spinning Color Wheel
QB64 Member Project - Martin Fractals version three
QB64 Member Project - Blokus
QB64 Member Project - Martin Fractals version one
QB64 Member Project - Dakapo
QB64 Member Project - Foursight
QB64 Member Project - Kobolts Monopoly
QB64 Member Project - Color Triangles
QB64 Member Project - Overboard
QB64 Member Project - Spiro Roses
QB64 Member Project - Splatter
QB64 Member Project - Color Rotating Text
QB64 Member Project - 9 Board
QB64 Member Project - Red Scrolling LED Sign