Go Back   Christian Guitar Forum > Community > Academic > Computers
Register FAQ Members List Calendar Arcade Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old 11-11-2009, 09:29 PM   #1
Be happy
 
bobthecockroach's Avatar
 

Joined: Apr 2001
Location: Louisiana
Posts: 19,716
40 ways to call a function

I'm creating a programming language. I'm currently planning to support more ways to call a function than I've ever even seen before. These are all perfectly legitimate ways to get x to the power of 2:

Code:
pow(x, 2)
x.pow(2)
(x, 2).pow()
(_, 2).pow(x)
pow(x)(2)  # Because just calling with x returns a partially-applied function. Hooray for currying!
pow()(x)(2)  # Calling with no arguments is ok too. This of course means that...
pow()()()()()()()()(x)()()()()()()()()(2)  # ...is also perfectly legitimate, if incredibly stupid.
x.pow()(2)  # would also be ok
(_, 2).pow()(x)  # of course is also fine.
The dot notation is just taken to be syntactic sugar for making something the first argument to the function. This is how extension functions in .NET work, so I'm not totally insane... yet. Where it gets insane is that you can use a tuple to syntactic-sugar-ly pass any number of arguments in this way.

Given the function:

Code:
takes x y z a b c:
    x * y + z - a / b ^ c
(There's no return statement either. Last value is returned. There's also no keyword to indicate a function declaration, or parenthesis around the arguments, or commas in between them. I might change this though to more closely match tuples and function calls.)

You can call:

Code:
takes(x,y,z,a,b,c)
x.takes(y,z,a,b,c)
(x,y).takes(z,a,b,c)
(x,y,z).takes(a,b,c)
(x,y,z,a).takes(b,c)
(x,y,z,a,b).takes(c)
(x,y,z,a,b,c).takes()
You can use _ as a placeholder to control which arguments are syntactic-sugar-ly passed. These all mean the same thing as well:

Code:
(_, _, _, a, b, c).takes(x, y, z)
(_, y, _, a, _, c).takes(x, z, b)
(x, _, _, _, b, c).takes(_, z, _)(y, a)
But you would really have to be out of your mind to do those.

I may change my mind on this, of course, but the reason is that if someone has written a really nice function that takes 6 arguments, and you want to partially apply it, but you want to partially apply it with the arguments in a different order, you should be able to do that. Of course, you could fake it with lambdas... but I don't have those yet either. Actually, lambdas are probably a better idea, so I'll probably scrap this, but the infinite number of syntactic-sugar-ly passed parameters is here to stay.

(Actually, I technically don't have anything at the moment because it's all just theoretical. I don't have a compiler or anything yet.)

... Now you know goes in bobthecockroach's head.

PS - If you're a JavaScript guru, you can help. This language is going to compile to (among other things) JavaScript.


Last edited by bobthecockroach; 11-11-2009 at 09:39 PM.
bobthecockroach is offline   Reply With Quote
Sponsored Links
Old 11-12-2009, 03:16 PM   #2
Wails, like a wombat!
 
Wailing Wombat's Avatar
 

Joined: Sep 2007
Location: Down under
Posts: 2,657
paid
Send a message via MSN to Wailing Wombat
You're insane.
Thats my opinion.
Why would you need that many ways to call a function?
Wailing Wombat is offline   Reply With Quote
Old 11-12-2009, 03:40 PM   #3
Registered User
 
kimberlyb0112's Avatar
 

Joined: Oct 2009
Location: Stationed out of Fort Campbell
Posts: 44
what the heck... this thread doesn't even look fun
kimberlyb0112 is offline   Reply With Quote
Old 11-12-2009, 03:49 PM   #4
indeed.
 
mtlmouth's Avatar
 

Joined: Jul 2004
Location: California
Posts: 9,698
paid
Could somebody please do a parody of "50 Ways To Leave Your Lover" based off this?
mtlmouth is offline   Reply With Quote
Old 11-12-2009, 03:58 PM   #5
Be happy
 
bobthecockroach's Avatar
 

Joined: Apr 2001
Location: Louisiana
Posts: 19,716
Quote:
Originally Posted by kimberlyb0112 View Post
what the heck... this thread doesn't even look fun
Ironically, I'm designing this programming language to be used for simple tasks or for people who aren't experienced programmers.
bobthecockroach is offline   Reply With Quote
Old 11-12-2009, 04:17 PM   #6
Wails, like a wombat!
 
Wailing Wombat's Avatar
 

Joined: Sep 2007
Location: Down under
Posts: 2,657
paid
Send a message via MSN to Wailing Wombat
Then you're totally crazy
If you want it to be easy, make it closer to english, too many ways to do one thing will just confuse people(Like me, I and do some programming)
Wailing Wombat is offline   Reply With Quote
Old 11-12-2009, 04:23 PM   #7
Registered User
 
Cam42's Avatar
 
Tournaments Won: 5

Joined: Apr 2008
Posts: 3,539
Quote:
, make it closer to english, too many ways to do one thing will just confuse people
English is better at this?
__________________
http://stopthewall.us/
Cam42 is offline   Reply With Quote
Old 11-12-2009, 04:26 PM   #8
Wails, like a wombat!
 
Wailing Wombat's Avatar
 

Joined: Sep 2007
Location: Down under
Posts: 2,657
paid
Send a message via MSN to Wailing Wombat
I'm meaning if you're trying to make it easier to learn for new programmers, its easier to learn something that is more similar to english compared to something that isn't.(High-level vs Low-level) And IMHO, thats just confusing(Although it could just the the excessive amounts of examples placed near each other)
Wailing Wombat is offline   Reply With Quote
Old 11-12-2009, 06:38 PM   #9
Be happy
 
bobthecockroach's Avatar
 

Joined: Apr 2001
Location: Louisiana
Posts: 19,716
Quote:
Originally Posted by TFK14 View Post
Then you're totally crazy
If you want it to be easy, make it closer to english, too many ways to do one thing will just confuse people(Like me, I and do some programming)
Trying to be like English is precisely what makes COBOL impossible to read:

Code:
    MULTIPLY QTR-BORROWINGS-FA BY ROYALTY-RATE-FA 
        GIVING BOOK-ROYALTY ROUNDED.
    ADD QTR-BORROWINGS-FA  TO QTR-AUTHOR-BORROWS.
    ADD BOOK-ROYALTY  TO AUTHOR-ROYALTIES, AGENT-PAYMENT.
    MOVE BOOK-NAME-FA TO BOOK-NAME-PRN.
    MOVE QTR-BORROWINGS-FA TO BOOK-QTR-BORROWS-PRN.
    MOVE BOOK-ROYALTY TO BOOK-ROYALTY-PRN.
    WRITE PRINT-LINE-FC FROM BOOK-LINE
             AFTER ADVANCING 1 LINE.

    MOVE ZEROS TO QTR-BORROWINGS-FA.
    REWRITE BOOK-REC-FA
        INVALID KEY
        DISPLAY "REWRITE 50-PROCESS-ONE-BOOK " BOOK-ERROR-STATUS
    END-REWRITE.
That's just insane.
bobthecockroach is offline   Reply With Quote
Old 11-12-2009, 06:40 PM   #10
Be happy
 
bobthecockroach's Avatar
 

Joined: Apr 2001
Location: Louisiana
Posts: 19,716
Quote:
Originally Posted by TFK14 View Post
I'm meaning if you're trying to make it easier to learn for new programmers, its easier to learn something that is more similar to english compared to something that isn't.(High-level vs Low-level) And IMHO, thats just confusing(Although it could just the the excessive amounts of examples placed near each other)
Right. And I'm also purposely showing something confusing.

A better thing might be comparing how to define a function to calculate a hypotenuse.

My language:

Code:
hypotenuse a b:
    sqrt(a^2 + b^2)
Python:

Code:
def hypotenuse(a, b):
    return sqrt(a**2 + b**2)
Java:

Code:
public double hypotenuse(double a, double b) {
    return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
}
Visual Basic:

Code:
Public Function Hypotenuse(a As Double, b As Double) As Double
    Return Math.Sqrt(a^2 + b^2)
End Function
One of the main goals of my design is to clear away everything that doesn't relate to the problem you're trying to solve. If you want to write a function to calculate a hypotenuse, the words "public", "double", "def", and "return" are unlikely to come to mind, and you certainly wouldn't see any need to use a lot of parenthesis and brackets. You probably wouldn't expect to tell the computer you're done giving it the function. "I stopped giving you information. I'm done! Figure it out!"

Once you know a few basic constructs (a name with a colon after it is a function, "sqrt" means square root, ^ is the exponentiation operator), you can see what my code is doing in a second. The Java code makes you write a bunch of stuff the computer cares about but you don't. COBOL does the same, it's just easier to guess the meaning of if you're not a programmer.

Last edited by bobthecockroach; 11-12-2009 at 06:51 PM.
bobthecockroach is offline   Reply With Quote
Old 11-12-2009, 10:12 PM   #11
Wails, like a wombat!
 
Wailing Wombat's Avatar
 

Joined: Sep 2007
Location: Down under
Posts: 2,657
paid
Send a message via MSN to Wailing Wombat
Point taken.
Wailing Wombat is offline   Reply With Quote
Old 11-12-2009, 10:15 PM   #12
Be happy
 
bobthecockroach's Avatar
 

Joined: Apr 2001
Location: Louisiana
Posts: 19,716
I welcome, now and in the future when I post more, any suggestions on readability. That's basically the number one goal for the language.
bobthecockroach is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -6. The time now is 11:47 AM.