This page contains all the information a new programmer needs to get started in Pysembly.
You need the following files installed on your machine:
1) Python - most recent version
2) Terminal or Windows Developer Shell (or other alternatives)
3) A code editor
And the folder at the Pysembly Download link.
Programs should go in the outer folder at the same location as the example program and readme.
Pysembly is a language based around the use of memory addresses (quite an old concept!) As a result, the basics of anything in Pysembly are storage and recall from a memory address. This is how you do that:
1) store (value) (prompt if input)
2) recall (address)
3) :)[text]
Firstly, the value. This is where you put the value you want to append to the memory list. If the value is "inp", it calls a user input with a prompt that you put after the inp declaration. If none is given, it defaults to "input requested by program". The recall instruction recalls the value at the provided memory address, indexed from 1. If the input starts with v, it just grabs the value at that memory slot - calling a variable. The third one is standard comment syntax, but everything that's not an instruction is ignored anyways so it doesn't make much difference. It's just that that is what demarcates a comment in CLIDE (a WIP pysembly IDE).
Note that code is not case-sensitive.
This is a quick addition to Syntax I detailing the use of delete, increment/decrement, and jump instructions.
The delete instruction is very simple. It simply works like the recall instruction, but deletes the value at the address, shifting all future addresses by 1.
Increment and decrement attempt to increment or decrement the value at the provided address.
Jump jumps to the provided line in the code.
delete (value)
increment (value)
decrement (value)
jump (line)
There are no actual parentheses in any of these, by the way.
This section details the difference between environment Pysembly and basic Pysembly, the two variants that are downloaded from the download on this site.
The syntactic rules are identical for basic and environment pysembly, but due to basic running directly in Python (whereas environment runs in a Pysembly environment), some changes have to be made.
The file structure for basic Pysembly is below:
code=[
'store Hello World',
'recall 1'
]
exec(open('pysembly4/pysembly4.1.py').read())
As you can see, this is not as easy as simply typing out the lines! This is because instead of being Pysembly code, the Pysembly code is wrapped in a layer of simple Python code. The Python code allows a basic OS to pick up the code and automatically execute it. The first lines save the code you input (in pysembly format) and the last line runs the actual code in Python. It is somewhat complicated but way easier than managing the environment, so I recommend you start here. The Python file containing the above structure is what is actually run. This form of code is still supported as of version 4.1.
The pysembly environment is much more complicated, but easier to execute code in. To do the following steps, you have to download and activate the file pysembly4.1ui.py. This file is the environment manager that interacts with the base pysembly4.1.py file to provide execution.
To start, when you open up the environment, you will be asked if you want to load a saved environment. If this is your first time, type NO (or indeed, anything other than YES) to skip this step. You will now be in the pysembly environment, where you can do a lot of things. When it asks you what app you wish to enter, press 0 for the application editor. Here you can write Pysembly code in a much simpler format:
[>= ]store Hello World
[>= ]recall 1
[>= ]end
Well, not quite. First it will ask you for a filename, to identify the code by. Then you get the actual code writer. That's when you can type in the code as shown above. Note that anything in brackets is system-output text. Remember the end marker to exit the code app. Then, give that program's number in the shown list (indexed from 0) to run it.
Here are some helpful shortcuts in the pysembly environment:
0: application editor - Allows you to write apps and run them
1: application viewer - Allows you to see code inside of apps
-1: application deleter - Allows you to delete apps
2 to n: Coded applications from the user
EXIT: Exits the environment
When exiting the environment, make sure to hang on to the oeSaveCode generated. This save code, along with holding the entirety of the environment you just exited, is the key to loading it back in. To load it back in, respond YES when prompted initially (see above) and paste in the save code.
A potential update to the environment to use a dedicated code editor for app editing is possible.
Pysembly 4.1 is a very different version of pysembly as compared to the rest of the versions. It merges the operating environment with the coding language to remove the python wrapper from basic code. To run pysembly 4.1 code, first create a text file with the pure syntax:
store hello world
recall 1
Put it in the same folder as the README, and change the extension to .psmb. Then, open terminal and navigate to the pysembly4 folder directory. For me, this uses the commands:
cd /Desktop/Pysembly/pysembly4
pwd (to make sure the directory is correct)
Then, run the command:
python3 pysembly4.1.py yourfile.psmb4
Replace yourfile with the filename of the program to be executed.
And that's it! The environment's newest version (4.1) is also compatible with pysembly 4.1.
Multi-line instructions! One of the major distinctions between Pysembly and other languages: in Pysembly, a majority of instructions in the language are multi-line. These include the arithmetic operators (add, subtract, multiply, divide), the conditional operator, and the loop.
add (input 1)
(input 2) (Syntax is equivalent for other operations)
if (input 1)
(operator)
(input 2)
(length of if)
repeat (input)
(number of instructions)
This is quite hard to unpack! Let's do it anyways! Firstly, the arithmetic operators. They add the second input to the value at the first input's memory address. Make sure you play around with using this operation, because it's really important. The if operation takes two inputs, an operator, and a time. Operators are: >, <, =, !, >=, <=. These mean greater than, less than, equal, not equal, greater or equal, and less or equal. The third input (time) is how many lines is encoded in the if. This one, while it could use indentation, is a holdover from Scratchsembly where that wasn't possible. Repeat is really simple. The input is the number of times to repeat. The second input is the number of INSTRUCTIONS (NOT LINES) within the repeat. Go figure, of course Python insisted on being annoying when I tried to make this language consistent. That is the essentials of the coding language, and there's just one more piece of syntax for especially high-level programmers - the Lines instruction. But that is for later.
If for some reason you really don't like multi line instructions, don't use them and put a line break marker between the parameters: " <&&> ". An example program that uses this for argument splitting is as follows:
store 1
add 1 <&&> 1
recall 1
For obvious reasons this is a reserved character.
There's only one piece of syntax left, but there are some auxiliary instructions that could be helpful.
Quit - exits program
Showmemory - prints memory
Showcode - prints code
Help - prints documentation
These are all useful for debugging, but based on the location and the running computer, Quit is sometimes somewhat buggy - sometimes it will cause Python to throw up an error when it tries to read the code, despite hours of me trying to fix it. Thus, avoid using it as much as possible.
Final piece of syntax (for now)! The Lines instruction is Pysembly's version of function definition. It allows your code to be more condensed and readable by calling a certain instruction or set of instructions multiple times throughout the code. It's really simple:
Lines (input 1)
(input 2)
The syntax is nice and concise. It starts at line number (input 1) and completes (input 2) instructions, before continuing with the execution of the program.
I lied - or rather, since the tutorial was written, three more instructions have been added. They're really simple.
psmb4 {code}
overwrite (input 1)
(input 2)
concatenate (input 1)
(input 2)
The first instruction simply executes given pysembly code - whether that's hardcoded or called by a variable, or even input by the user. The second and third are simple operators, similar to the arithmetic from above. The first replaces the value in a given memory slot (input 1) with the provided value (input 2), and the second concatenates (input 2) to the memory slot at (input 1). Another operator to add deconcatenation/splitting is in development.
Well, there you have it! The entirety of the syntax and useful instructions for Pysembly V4 and Pysembly Environment V4! Now, what are you waiting for? Create something incredible! (or don't, it's up to you). Email me your coolest creations at neptunetranscripts@gmail.com. Want to add to the language? Send me the codeblock! The possibilities are limitless. Have fun!
No coding language got to where it is on its developers' vision alone, and pysembly is no exception. That's why, starting in the most recent version of pysembly (available for download), the definition of custom modules is now possible. Simply create your module python file, and name it based on its usage. So, your first module would be pysembly4m0.py, the second would be pysembly4m1.py, etc. Then just put the modules into the pysembly4 folder (see folder structure) and the contents of them are automatically run by the interpreter.