This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#6676 2013-01-29 05:57:05

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

factorial n = product [1..n]

factorial := n\(1..n) product

: factorial ( n -- n ) [1,b] product ;

×/″ι″N

Hmpf. I didn't really understand any of those, and that's part of my problem with these languages.

My language would ideally be as verbose as possible, but not excessive with keystrokes. Basically, I would minimize the number of non-alphabetical symbols used.

define factorial as
   function n (default 5, n is a Number)
      n*(factorial n-1)

factorial 5
map factorial over [1,2,3]
factorial (factorial 5)

Another totally new feature I'm mulling over is a special syntax for "units". So I should be able to define something like this:

define unit in as
   function n
      new Inch n

move 5in => move (new Inch 5)

Also, instead of classes, I'd prefer having a kind of "factory" which generates a custom dictionary object, kind of like JS but sleeker:

define type Inch as
   {
      _initialize_:function self n (n is a Number, default 1)
         set self.value to n
      toFeet: function self
         self.value/12
   }

(new Inch 5).toFeet

Notice how in many functions, I have "label text". That's intentional, and should behave like BYOB/Snap!. I want to be able to make special functions like

define map as
   function f (f is a Function) "over" l (l is a List)
      set newL to EMPTY_LIST
      for i in l
         add (f i) to newL
      return newL

map
   function n
      n*2
over [1,2,3,4,5]

And while I'm on special forms, how about this?

define for as
   function i (upvar) "in" j (j is Iterable) "do" f (unevaluated)
      // implementation skipped over...

for item in [1,2,3]
   print item*10

(bad example, but it shows the point).
Don't ask me how I'm planning to parse all that stuff, but I think it's both possible and worth it.

In other news, I managed to get Snap! file I/O working haphazardly, and have managed to raytrace a nice, patriotic "S".  big_smile  Now to figure out why it's half-sunken into the ground...

Last edited by Hardmath123 (2013-01-29 06:01:13)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#6677 2013-01-29 10:44:17

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

define map as
   function f (f is a Function) "over" l (l is a List)

You've put a lot of thought into this, and have some really interesting ideas.  (I especially like units, although it's going to be a little painful to get arithmetic of values with units correct.)  But in the example above, why do you treat the word map so differently from the word over?  They're both part of the name of the function, and privileging the first word rules out infix operators.  How about

define function
    map (Function f) over (List l)
as
    ...

This wouldn't have to be strongly typed; you could say

define function
   map (f) over (l)

In other news, I managed to get Snap! file I/O working haphazardly

By running a Snap! server on your own computer, or did you persuade a browser to do file I/O?


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#6678 2013-01-29 10:47:05

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: BYOB 3 - Discussion Thread

factorial n = product [1..n]

factorial := n\(1..n) product

: factorial ( n -- n ) [1,b] product ;

×/″ι″N

Fewest keystrokes, eh?
OK, I'm using Snap!. I click the "make a block" button, type "!" (1 keystroke), make an  input called n (1 keystroke), then do

report <if <(n) = (0)> then (1) else ((n) * <((n) - (1)) !>)>
(i'm using the if/then/else block in the tools library)
I only have to type the numbers (3 keystrokes), making a total of 5 keystrokes, beating your APL version of 6 keystrokes. I win.

I don't really like APL because I can never remember what all the weird symbols are for  sad

Last edited by joefarebrother (2013-01-29 15:51:37)


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#6679 2013-01-29 11:36:13

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Hardmath123 wrote:

define map as
   function f (f is a Function) "over" l (l is a List)

You've put a lot of thought into this, and have some really interesting ideas.  (I especially like units, although it's going to be a little painful to get arithmetic of values with units correct.)  But in the example above, why do you treat the word map so differently from the word over?  They're both part of the name of the function, and privileging the first word rules out infix operators.  How about

define function
    map (Function f) over (List l)
as
    ...

This wouldn't have to be strongly typed; you could say

define function
   map (f) over (l)

So I would reference a function as map:over: selector-style? That's one thing I really don't like about languages like Obj-C and Squeak. Names of functions and any other variables should be the same, so that really functions are just variables. So the first "word" in a "sentence" is always some expression which returns a function, and the rest are arguments. An argument can optionally also be part of the "label text", in which case it is only present for readability: "set x to 5" makes more sense than "set x 5".

Actually, I only have 3 types of definitions: define unit, define type (classes!), and plain ol' define. The arguments to define are just the name and the value. So in the example, I was assigning a lambda to the name map. I'm using the latter of the below:

Code:

(define (f x) (x))
(define f (lambda (x) x))

In other news, I managed to get Snap! file I/O working haphazardly

By running a Snap! server on your own computer, or did you persuade a browser to do file I/O?

Python server.  big_smile


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#6680 2013-01-29 15:37:22

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

Names of functions and any other variables should be the same, so that really functions are just variables. So the first "word" in a "sentence" is always some expression which returns a function, and the rest are arguments. An argument can optionally also be part of the "label text", in which case it is only present for readability: "set x to 5" makes more sense than "set x 5".

Is the "to" required or optional (in a call)?

One of the advantages we get from title text beyond the first word is that we can sort of overload names, e.g., we have
   for (i) = (1) to (10)
and we also have
   for each (item) in (list)
and this works because the full names of the procedures include the entire text (and the places for inputs).  It sounds like you can't do that in your language, because "for" is just a variable that has one procedure as its value.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#6681 2013-01-29 15:43:50

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

Another totally new feature I'm mulling over is a special syntax for "units". So I should be able to define something like this:

define unit in as
   function n
      new Inch n

move 5in => move (new Inch 5)

Yeah, I made a language that did that a while ago with some friends. The syntax was just:
unit m (for base units)
unit mm = 1e-4 m (for prefixes)
unit N = kg m / s^2 (for derived units)

And it would do calculations and unit conversions for you:

> 10 m/s^2 * 5.3 hours / 3 inches in MHz
< 2.50393701 MHz

(it also had lambdas, which is why I said "language" and not "fancy calculator")

The problem with using "new" is that it's likely to mislead C/Java programmers, and doesn't actually make a new anything—it just attaches a unit.

Regarding the label text discussion: I've always thought the way Python did it was nice. All arguments can be passed as named arguments or positional arguments, and functions can take variable amounts of both named and positional arguments. If you have an assignment operator, though, you'll have to use a syntax different from (@bharvey  wink ) func(a, b, c=d, e=f)

If you want to use labels interspersed between arguments (and not just named arguments), I wrote a scratchblocks parser that is reasonably skilled at determining what you mean without hordes of parentheses (e.g., `set a to item 2 + 3 * 4 of positions + 10' instead of `set [a] to ((item ([2] + ([3] * [4])) of [positions v]) + [10])'), and can send you the source/give you some help if you need any.

Last edited by nXIII (2013-01-29 15:47:31)


nXIII

Offline

 

#6682 2013-01-29 16:41:26

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: BYOB 3 - Discussion Thread

nXIII wrote:

If you want to use labels interspersed between arguments (and not just named arguments), I wrote a scratchblocks parser that is reasonably skilled at determining what you mean without hordes of parentheses (e.g., `set a to item 2 + 3 * 4 of positions + 10' instead of `set [a] to ((item ([2] + ([3] * [4])) of [positions v]) + [10])'), and can send you the source/give you some help if you need any.

That sounds clever. Can I see?  smile


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#6683 2013-01-29 17:38:43

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

blob8108 wrote:

nXIII wrote:

If you want to use labels interspersed between arguments (and not just named arguments), I wrote a scratchblocks parser that is reasonably skilled at determining what you mean without hordes of parentheses (e.g., `set a to item 2 + 3 * 4 of positions + 10' instead of `set [a] to ((item ([2] + ([3] * [4])) of [positions v]) + [10])'), and can send you the source/give you some help if you need any.

That sounds clever. Can I see?  smile

It's PHP and it's not hosted anywhere.  tongue


nXIII

Offline

 

#6684 2013-01-29 21:40:55

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

nXIII wrote:

unit N = kg m / s^2 (for derived units)

If this:

http://cs.berkeley.edu/~bh/cm.png

is a centimeter, what's this:

http://cs.berkeley.edu/~bh/cm2.png

?


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#6685 2013-01-29 22:12:37

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

nXIII wrote:

unit N = kg m / s^2 (for derived units)

If this:

http://cs.berkeley.edu/~bh/cm.png

is a centimeter, what's this:

http://cs.berkeley.edu/~bh/cm2.png

?

An upside-down centimeter? Sorry, I don't understand your question.

Last edited by nXIII (2013-01-29 22:13:03)


nXIII

Offline

 

#6686 2013-01-29 22:50:40

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

nXIII wrote:

Sorry, I don't understand your question.

It's a riddle!  One of you unit fans will get it...


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#6687 2013-01-29 23:24:02

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

nXIII wrote:

Sorry, I don't understand your question.

It's a riddle!  One of you unit fans will get it...

-1 cm?
cm^-1?


nXIII

Offline

 

#6688 2013-01-29 23:28:35

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Hardmath123 wrote:

Names of functions and any other variables should be the same, so that really functions are just variables. So the first "word" in a "sentence" is always some expression which returns a function, and the rest are arguments. An argument can optionally also be part of the "label text", in which case it is only present for readability: "set x to 5" makes more sense than "set x 5".

Is the "to" required or optional (in a call)?

Required, but there's a special function called "run":

Code:

define f
   function x y z
      return x + y + z
run f with arguments 10, 11, 12
run f with list [1,2,3]

Also,

Code:

run f with current continuation

big_smile

One of the advantages we get from title text beyond the first word is that we can sort of overload names, e.g., we have
   for (i) = (1) to (10)
and we also have
   for each (item) in (list)
and this works because the full names of the procedures include the entire text (and the places for inputs).  It sounds like you can't do that in your language, because "for" is just a variable that has one procedure as its value.

I don't want to do that either, then it's not as intuitive to pass functions as arguments (in Obj-C you use @selector(a:b:c smile  which is really complicated and yucky. They also have "blocks" which are like lambdas except very strictly typed. The compiler infers the return type.  sad ).


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#6689 2013-01-29 23:34:07

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

nXIII wrote:

Hardmath123 wrote:

Another totally new feature I'm mulling over is a special syntax for "units". So I should be able to define something like this:

define unit in as
   function n
      new Inch n

move 5in => move (new Inch 5)

Yeah, I made a language that did that a while ago with some friends. The syntax was just:
unit m (for base units)
unit mm = 1e-4 m (for prefixes)
unit N = kg m / s^2 (for derived units)

And it would do calculations and unit conversions for you:

> 10 m/s^2 * 5.3 hours / 3 inches in MHz
< 2.50393701 MHz

(it also had lambdas, which is why I said "language" and not "fancy calculator")

The problem with using "new" is that it's likely to mislead C/Java programmers, and doesn't actually make a new anything—it just attaches a unit.

Regarding the label text discussion: I've always thought the way Python did it was nice. All arguments can be passed as named arguments or positional arguments, and functions can take variable amounts of both named and positional arguments. If you have an assignment operator, though, you'll have to use a syntax different from (@bharvey  wink ) func(a, b, c=d, e=f)

If you want to use labels interspersed between arguments (and not just named arguments), I wrote a scratchblocks parser that is reasonably skilled at determining what you mean without hordes of parentheses (e.g., `set a to item 2 + 3 * 4 of positions + 10' instead of `set [a] to ((item ([2] + ([3] * [4])) of [positions v]) + [10])'), and can send you the source/give you some help if you need any.

"New" basically creates a new instance of a class. So Inch is a class, and the unit "in" is actually a lambda which takes an argument and returns an Inch object with the argument. That way I can have any arbitrary type of unit, not limited to numbers, including things like [0,5]point or [255,255,230]color. That basically makes readability easier:

Code:

move 5in forward
square at [0,0]point side 3px
turn 5deg ccw
turn (math.PI)rad cw

Kind of like CSS!


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#6690 2013-01-30 00:31:50

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

"New" basically creates a new instance of a class. So Inch is a class, and the unit "in" is actually a lambda which takes an argument and returns an Inch object with the argument.

…so calling is postfix?

That way I can have any arbitrary type of unit, not limited to numbers, including things like [0,5]point or [255,255,230]color. That basically makes readability easier:

Code:

move 5in forward
square at [0,0]point side 3px
turn 5deg ccw
turn (math.PI)rad cw

Kind of like CSS!

In CSS, units are always attached to scalar values. This just looks like an alternate form of constructor. Are you planning on doing unit conversions?


nXIII

Offline

 

#6691 2013-01-30 00:47:50

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

nXIII wrote:

-1 cm?
cm^-1?

Nah, c'mon, I wouldn't ask you a stupid riddle!  You'll know you've figured it out because it'll be funny.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#6692 2013-01-30 00:49:21

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

A millimeter? A millipede?


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#6693 2013-01-30 00:50:45

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

nXIII wrote:

In CSS, units are always attached to scalar values. This just looks like an alternate form of constructor.

Yes, I suppose it is kind of like a constructor, but more like an abbreviation.

Are you planning on doing unit conversions?

Yeah, otherwise why not just use raw numbers?  tongue


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#6694 2013-01-30 00:57:49

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

That way I can have any arbitrary type of unit, not limited to numbers, including things like [0,5]point or [255,255,230]color.

That's not really much different from "[0,5] Point" -- just a postfix notation for constructors.  Point and color aren't really units at all.  (Well, point is, if you mean 1/12 of a pica, but not the kind of point you mean.)  Units have a whole algebra; they come in categories (distance units, time units, etc.) that interact in funny ways.  You can add unit-tagged numbers of the same category (inches and meters, say) but not of different categories (inches and hours).  But you can multiply inches by hours, in principle, although it makes more sense to divide inches by hours (to get the speed of a turtle  smile ).  And if you multiply two units of the same category you get a result in square whatevers.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#6695 2013-01-30 00:59:14

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

A millimeter? A millipede?

I'll tell you tomorrow...


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#6696 2013-01-30 02:44:33

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Noooo… the suspense…

Well, ideally I'd have Python-style wrappers (_mul_,_add_,_sub_,_div_) so that units can be custom-mixed, too, so that I can multiply colors:

red-blue=purple

or something.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#6697 2013-01-30 11:23:48

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

Noooo… the suspense…

It's... (drumroll, please) ... an erg.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#6698 2013-01-30 14:55:23

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

Well, ideally I'd have Python-style wrappers (_mul_,_add_,_sub_,_div_) so that units can be custom-mixed, too…

That's just operator overloading and postfix constructors…


nXIII

Offline

 

#6699 2013-01-30 17:47:30

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

so that units can be custom-mixed, too

The thing is, real units have a whole set of common structure that aren't shared with things like colors.  Just off the top of my head, a category (say, distance) has subcategories based on systems of units (metric, English), so if you add feet to meters you should get an answer in meters, but if you add feet to inches you should get an answer in inches (although a really smart implementation would notice if the answer you get is either extremely large or extremely small and switch units accordingly).  And there'd be a database of conversions across categories, so (to take one of n's examples) an answer in sec^-1 would be converted to Hz.

If you conflate units with other types, you're losing all that structure, which you then have to build by hand.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#6700 2013-01-30 20:08:22

Sidharth
Scratcher
Registered: 2007-12-14
Posts: 100+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

My language would ideally be as verbose as possible, but not excessive with keystrokes. Basically, I would minimize the number of non-alphabetical symbols used.

Try inform  smile

I know it doesn't suit your purpose, but it is very interesting.


http://www.danasoft.com/citysign.jpg

Offline

 

Board footer