First time coding in PHP and I hate it. It's an inconsistent clusterfuck.
1+"1" is ok and returns int but "str"+"str" is an error and you have to use . and if you do "1"+"1" it's ok and turns into an int
There are also multiple ways to do the same. To convert a number to a string you can either cast it or use use strval()![]()
@matrix 1+"1" or "1" + "1" is addition
"str" . "str" is a concatenation
Lua has the .. op for concatenation, and I think some other languages do the same or similar
@applejack I understand. I hate the implicit retyping. Logically "1" + "1" should throw an error because you are trying to put together two strings.
@matrix I think if you have separate operators it's not that bad, otherwise it's more typing
@Shlomo No I haven't
@Shlomo Yeah, that doesn't look fun
@matrix I’m afraid @Shlomo is well named, this is a terrible problem to try to demonstrate code for any language, and what we can see of the example code it is also bad.
Fizz buzz this is not, it’s trying to compute “a member of a family of related integer sequences defined by non-linear recurrence relations,” a https://en.wikipedia.org/wiki/Hofstadter_sequence
Then the code isn’t even properly formatted: compare the first and second if’s, the second is correct, vertically aligning the test and true and false return values. If you don’t use a minimally smart editor or in the bad old days a coding form before it’s punched to cards you’re in for a world of hurt.
On the other hand it’s interesting in that lambda creates a function to use later in the code, and letrec gives the functions names to keep the global namespace clean. Otherwise you could create both using define outside of the function that’s being defined. Being able to create functions on the fly, making them “first-class” so they can be used as arguments to other functions and returned by them, is very powerful. For a much more limited example, see the classic qsort in the C standard library: https://en.wikipedia.org/wiki/Qsort
Then there’s not enough code to comment on especially since it’s too late in the day for me to even think about anything pertaining to sequences other than learning “The On-Line Encyclopedia of Integer Sequences® (OEIS®)” exists: https://oeis.org/ And close with what per Wikiquote is a bogus quote from Abraham Lincoln which I first read in a Scheme paper: “People who like this sort of thing will find this the sort of thing they like.” Sequences for their own sake never interested me, but you can use them to do cool things.
@matrix Appears you are one of millions who’ve learned that if your name isn’t John Backus or John McCarthy you should seriously study programming language design before you create your own language, we now know a lot more. You should also be very sure that you have good taste.
See also languages like Python which apparently can’t be made to go fast, something I gather isn’t such a big problem for PHP.
(Anyone who wants to complain about my not including Grace Hopper should look at this: https://en.wikipedia.org/wiki/FLOW-MATIC
I’ll bet it was really cool when it came out, but see the above “we now know a lot more,” and of course both FORTRAN and LISP evolved from modest beginnings. I can from a bit of direct experience say COBOL is pretty cool for ripping through files of fixed length records….)