computer science: environments

All material and examples comes from UC Berkeley. Synthesis & inaccuracy is fault of my own, not that of UC Berkeley’s EECS Department. Note that I have not formally taken a CS class, rather do self synthesis. These posts are more so for me to explain it out in a way that I have come to understand and can referrence to later on rather than trying to make it a tutorial.

Computer science programs operate in different series of interrelated environments, which is a mapping from names to values. Global is the encompassing environment frame. Global is often referred to as Parent as well. Subexpressions are evaluated in expressions within its environment. Once evaluated, calls to user-defined functions must evaluate the expressions and statements from the definition of those functions.

If you had code that read:

from operator import mul

def square(x):

return mul(x,x)

x = – 2

Your global would be: mul, square, x

Your expression evaluation would be: square(mul(x,x))

Replace x with -s, so square(mul(-2,-2))

square(-2 * -2)

square(4)

16

 

javascript: javascripting

I finished this program the other day from nodeschool that teaches you the basics of JavaScript. The very first one ‘javacripting’s is great for ultimate beginners. If you know nothing of code, this is a good way to delve into a test-driven method for learning JavaScript. If you already know the basics of coding, you’ll find this a breeze. All the same, it’s a good way to learn JavaScript syntax. If you’re totally new to coding and want to check this out, here’s a simpler step-by-step for you.

 

What you’ll need:

  • Terminal open (Finder>All Applications>Terminal)
  • A text editor (I use Sublime)
  • Download this (which makes nodeschool work)
  • The ‘javascripting’ will redirect you to this GitHub, but if GitHub makes you auto-delete the tab and give up on the spot, do not worry
    • type this into your terminal:
    • npm install --global javascripting
    • then type ‘javascripting’ into your terminal and run it

Getting Started

For orgizational purposes, it’s suggested you make a new directory for these exercises. Let’s call it: javascripting. To do this from you terminal type the following:

  • mkdir javascripting, hit enter (make a directory called javascripting)
  • cd javascripting, hit enter (changes your directory to javascripting, meaning that you are working and creating in this directory from the terminal; so when you save your programs from the text editor, make sure that they’re being saved into this folder)

The First Program

The first program has you print out ‘hello’ from your text editor to your terminal– sounds totally crazy. The code has been given to you // console.log(‘hello); // . Then save this file (into your javascripting folder!) as something simple, like javascripting.js. The .js is super important so that your text editor knows it’s running a JavaScript file. You should also get some pretty cool colours in your text editor! Once you’re all saved, type //javascripting verify javascripting.js // into your terminal and press enter. You’ve finished the first program!

 

This was a very brief introduction to a nodeschool program and how to set everything up, in case you’re one who feels discouraged just at the sight of GitHub or perhaps didn’t know what the terminal was. Well, now you do! I’ll get more into other node schools later and explain more thoroughly just what the code is actually doing, aside from syntax.