this board needs more threads. i'm currently trying to fight my way around ocaml and am kind of astonished at the syntax. i, being used to c/c++/ruby/perl conventions, find myself more or less lost even in what seems like a simple snippet of code. at first, i became interested in ocaml because i heard it was right behind c in terms of performace while providing the programmer with bound checking, a garbage collector, OO, and other neat features like type inference, where the compiler guesses the type of the variable by means of looking at what is done with it. some tiny examples, taken from the first 2 chapters of http://merjis.com/developers/ocaml_tutorial/, "Learning OCaml, for C, C++, Perl and Java programmers":
> let average a b =
> (a +. b) /. 2.0;;
this defines a function "average", which takes 2 floats as arguments and returns the average of them. "+." and "/." are operators acting on floating point thingies, there is no such thing as implicit casting.
> The standard phrase "let name = expression in" is used to define a named
> local expression. [...]
> The C variable sum has a slot allocated for it on the stack. You can
> assign to sum later in the function if you want, or even take the
> address of sum. This is NOT true for the OCaml version. In the OCaml
> version, sum is just a shorthand name for the expression a +. b. There
> is no way to assign to sum or change its value in any way. [...] Here's
> another example to make this clearer:
> [...]
> let f a b =
> let x = a +. b in
> x +. x ** 2.
> ;;
> The ; is an operator, just like + is. Well, not quite just like + is,
> but conceptually the same. + has type int -> int -> int - it takes two
> ints and returns an int (the sum). ; has type unit -> 'b -> 'b - it
> takes two values and simply returns the second one. Rather like C's ,
> (comma) operator. You can write a ; b ; c ; d just as easily as you
> can write a + b + c + d.
yarrr >_>. read chapter 2 for more of this kind of stuff. things like nested functions, global definitions, some real code examples, "; vs ;; vs none" and assignement of "real" variables await you. check http://en.wikipedia.org/wiki/Ocaml for an ocaml implementation of "99 Bottles of Beer" :O.
anyone up to share his experience with languages which left you mystified or feeling stupid?
Perl. When I look at Perl code, it's almost at the level where I really just don't even want to try to understand it. Stuff like where there's an "if" clause after the action the program should take if it's true...
But this OCaml looks almost as horrific... Why are you subjecting yourself to it?! If you already know C and are looking for another lang which has OO and other goodies, have you considered Objective C?
>>3: Thank you for your post. Your contribution to the topic at hand is immeasurable.
Unlambda or Malbolge. I made the mistake of talking weird languages with WAHa once, and he had those little nuggets of evil tucked away.
I guarantee you've never seen languages this bad.
"if" after the expression seems strange at first when you're used to C, until you realize it's just English: "Do this, if that". The "unless" construct makes it even easier to read your code out loud. $name="Anonymous" unless($name)
- "Set $name to Anonymous unless there's a name already".
Unlambda is fascinating. Most weird languages I can look at and think, wow, it must be a pain to try and program in this, but usually I can at least imagine how you do it. With unlambda, I am totally lost. I guess I don't have enough background in functional languages, because I really don't even know where to begin with that one.
>>2
i guess i'm holding out out of pure curiosity. as for objective c, thanks for pointing it out, neat stuff. sticks out like a sore thumb in a regular c program though :O.
Probably a good idea. Every programmer should know at least one functional language.
>>7 Shut yo mouth! Esolangery (the study of languages like Malbolge [sic] and Unlambda) is a great way to kill both time and brain cells. Though they aren't as polished as BrainF*ck or Befunge, they are so bafflingly warped that they deserve their own place in the world.
>>9 Unlambda is basically just an elaborate cypher for Scheme, only with the goddamn v c and d to confuse people. I just copy and paste stuff from the examples into a collage of operators. It's a fucking bitch, though, and not as interesting as Thue or Shelta
I suppose I should mention perl.
Perl itself is fairly straightforward but has all kinds of hidden behaviors to trip the newcomer. The first time I started developing something in perl I recall bashing my head against the wall for an hour at a time over several weeks.
Once I figured it all out I promptly forgot most of it and just started using a limited subset of the language instead.
Perl's great, but beware that first step.
>"if" after the expression seems strange at first when you're used to C, until you realize it's just English: "Do this, if that".
Mmh... English can go both ways, though; "If that, do this."
I guess it's just what I'm used to. I mean, the first lang I coded in was C=64 BASIC: IF Y=10 THEN Y=0
.
Naming languages which are intentionally obfuscated is cheating. :P Let's stick to langs that people actually use... In the many langs that have it, the function of lambda functions often eludes me, or why I would want to use one.
But the ordering Perl uses usually flows better as natural language. The problem with it, though, is that it doesn't allow an else statement. But that's not what it's for - it's for the really simple conditional lines, like my example above.
Or switch statements.
{ foobar; break;} if /abc/;
{ xyzzy; fall_through(); } if /xyz/;
{ pedobear; break; } if /dqn/;
default;
any discussion about arcane programming languages should not go without the mention of Whitespace and SPL
the sheer genius of the second one (Shakespeare Programming Language) is of particular interest
SPL is definitely brilliant, but Whitespace is just Brainfuck, isn't it?
http://compsoc.dur.ac.uk/whitespace/
Whitespace is a programming language in which the program is written using only the space, tab and newline characters. All other characters are ignored. Here's Hello World in Whitespace:
http://compsoc.dur.ac.uk/whitespace/hworld.ws
I wonder what would happen if I submitted a printout of an assignment in Whitespace to my professor...
I see. Whitespace is invisible brainfuck.
Looking a bit closer, it looks more like False than Brainfuck, but still.
Lingua::Romana::Perligata is still crazier.
>>16
there is no 'break' or 'default' keyword in perl
here is a cool thing:
&{ {foo=>sub{print "poop"; eat_poop()}, bar=>sub{print 1..100}, dick=>\&punch}->{$which} }
equivalent to
switch($which) {
case 'foo':
etc.
Intercal!!
As for a (potentially) realistically interesting language, anyone used Haskell? It was developed by some guys over in Scotland, I think. It's a pure functional language.
We were taught it in COMP1A by our brilliant but scatterbrained lecturer, and it annoyed the hell out of me. It's got some good points, and it eats recursion for breakfast, but functional programming takes getting used to, I guess.
Still, you can use it for CGI stuff, so it's amusing in that respect. I also understand that the compiler was written in Haskell and compiled with the Haskell compiler, so... compilation recursion!
On the topic of functional languages, there's one thing that pisses me off no end in OCaml: record labels all have a single namespace.
It's the strangest design decision I've ever seen in a language. For added hilarity, it seems the majority of functional languages contain this stupidity too. Have I missed something?
OCaml also has all these dumb quirks by default, like allowing either or or ||, but while you can use && you can't use and, because and is used for something else.
Not exactly major flaws, but it's like death by a thousand cuts.
Objective-C is driving me up the walls. On the one hand, it does many things that are very nice: Message passing through a dispatcher instead of method calls as functions makes it very flexible for GUI work (although I wouldn't want to use it for anything else, as it would just be a performance hit), and overall the language has a great deal of reflection. It also has a class library that contains a whole lot of useful functionality.
However, it gets none of this QUITE right. The message passing syntax is ugly as sin, and uses named parameters. You'd think this would let you give parameters in any order, but you can't. To add insult to injury, the method names can be as long as several sentences, making them utterly impossible to remember, and forcing you to keep the reference docs open at all times. There exist monsters like "–initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:"
The memory allocation is somewhere half-way between manual and garbage-collected, combining the drawbacks of both. And there are lots of weird quirks, like how you always have to use pointers to objects, and objects-by-value are forbidden entirely.