PandaBETA

A PANDA'S BEST FRIEND

| About | Learn | Documenation | Tutorial | Funcs | Types | Libraries | Blog | Report a bug |
NEWS2016-06-28

Invited to talk at Strange Loop / SEPTEMBER 15-17 2016 / ST. LOUIS, MO, USA.

HOW WOULD A PANDA PROGRAM COMPUTERS?

Panda is...
a new innovating programming language (2016). One goal is to make programming fun again... It has several characteristcs:

Read the manual!

Justifications: Programming...







WARNING: Panda is a concept in progress, still changing and breaking...

You can try it out in the command line Interactive Panda.

(Other GUI oriented clients are being developed: panda touch, panda write, panda sheet)

Simple example

Take the numbers 1 to 10, keep the odd ones and then square them. Keep the squares less than 50!

Panda:


Details: Points:
Panda only has functions. A function can return several times. If it returns:

odd either returns nothing, or one value, if it's an odd integer. to is a generator, returning increasing integers each time

In this case we have use 4 functions:

In plain old C - ala 1972


      #include 
        
      void main() {
        int i;
        for(i = 1; i <= 10; i++) {
          if (i % 2 == 1) {
            int s = i * i;
            if (s < 50)
              printf("%d ", s);
          }
        }
      }
      
Details:
  1. #include <stdio.h> - why you need to tell it to know how to print? It's a computer, can't it print?
  2. int i - i is assigned 1, it's an integer, so figure it out!
  3. i - why it needs to named? i means what?
  4. i <= 10 - up to including 10, however most loops start at 0 and use < boundary and +/- 1 bugs are very common
  5. for( &nbpsp; ; &nbpsp; ; &nbpsp;) - interesting syntax '(' ';' ';' ')'
  6. { - start of "block"
  7. i % 2 - modulo, fine it's an operator 'mod' may not be much clearer if you're programmer
  8. == 1 - if the result is 1
  9. i % 2 == 1 - wait a momement! What does this mean? if i dividided by 2 and the rest is 1... - ah ODD!
  10. int s - again, we're telling the computer what to store "allocated 4/8 bytes"
  11. s - oh, yeah, s is short for square, right...
  12. i * i - simple definition of square
  13. s < 50 clear, not including 50
  14. printf - printf(ormatted), is there another print?
  15. "%d " - print the following, an integer with no formatting(!) followed by one space
  16. } } } - eh, ok, just checking your indentation, for you not to make mistakes

haskell - future ala 1990


      main = mapM (\v -> putStrLn (show v)) $
             filter (< 50) $
             map (\j -> j * j) $
             filter odd $
             let incr a = a : incr (a+1) in
             take 10 $
             incr 1
      
Details:
  1. mapM - ok I'm mapM all day!
  2. (\v -> ...) defining a function that takes a single parameter v
  3. (putStr show v)) I'm putt'n a Str that I show'd you?
  4. $ - dollar makes the world go around!
  5. filter - am I filtering?
  6. (< 50) - Ok, shorthand, reads fine-ish
  7. $ - more money!
  8. map - I'm mapping!
  9. $ - I'm getting rich!
  10. filter odd - filter odd - does that filter out or filter to keep?
  11. let - basic let revived!
  12. incr = a : incr (a+1) - a function 'incr' that given a number will return a list starting with it and continue with calling myself ('incr') with the next number (infinite lazy recursion)
  13. in - given those lets, ok here comes the actual expression...
  14. take 10 - yeah: give me 10 numbers
  15. $ - why don't we just add a dollar to every line? (no we missed one...)
  16. incr 1 - call the function 'incr' that we 'let' above with 1. It'll give 1,2,3...

Haskell list comprehension


      [s | i <-- [1..10], odd i, let s = i * i, s < 50]
      
That's cool! However, still..