« first day (1685 days earlier)      last day (3322 days later) » 

12:00 AM
Known issue
If you mean Meta, Meta's not HTTPS
Well the above link is HTTPS
Yeah
Glares at New Sandboxed Posts
I'm working on adding lambdas to PGS, and I feel that there has to be a better way to do it.
I'm going to have to use some advanced tools...
12:11 AM
@PhiNotPi PGS?
@Alex can explain.
Clearly, PostGreSql
Anyways, I am creating a new programming language.
Programmatic Gene Splicing
12:14 AM
PGS is an abbreviation for a name Alex made up, since the language doesn't have a name yet.
@PhiNotPi Oh I see.
@PhiNotPi What paradigm?
Pretty Good Stuff?
Programming Gone Steroidal?
ehhh.... it's going to be a little mixed. In some sense, it's stack-based, but I'm attempting to add lambdas, which are not stack-based.
@PhiNotPi Interesting ^_^
PGS == Phi's Golfo Supreme
12:17 AM
XD
PGS :?= "Perambulating gripping saturnid"
Procrastinating Geek Syndrome
(describes me to a tee...)
@Timwi Story of my life. :P
Here's my current programming question, for those Perlites out there. I have two ananymous subroutine references, stored in local variables. I want to create a new anonymous subroutine that runs both of those other subroutine. How do I do it?
sub runboth() { my ($first, $second) = @_; $first->(); $second->(); }
Am I missing something?
Oh, anonymous. Er, my $runboth = \{ <the above> }; ?
If I change the value of $first later on, would that change the action of the subroutine? I don't want it to.
Wait, that wouldn't be the problem.
12:26 AM
Oh, OK. Then you’ll need to wrap it in a closu— oh OK then :)
The problem would be that, this runboth() takes the two things to run as arguments.
I want to create a runboth that takes no arguments.
my $runboth = \{ $first->(); $second->(); }; ?
Assuming the variables are already called $first and $second.
Would changing the values of first and second later on change the action?
Yes
OK how did you do the monospace in the end? :)
VGFicwlmb3IJdGhlCXdpbgkh
12:32 AM
@Timwi ¯\_(ツ)_/¯
(backticks, I just had a misplaced \)
Oh OK
Single or double quotes? :3
I'm going to have to do some serious re-working of my lambda system if I can't get this to work.
@PhiNotPi There's nothing worse than redoing code, IMO
@PhiNotPi you here?
12:38 AM
yes
considering you asked that question, I have a suspicion you don't know something you want to know
that may or may not amaze you and blow your mind
you understand python, right?
using lambda functions ONLY, write a recursive function
No clue.
Y combinator?
12:39 AM
@Timwi shhh
this is a learning experience
@Timwi I thought that was a venture capital company.
not a googling experience
Hey, I specifically waited until he said “no clue”
@Timwi Why are your quotation marks weird?
I did this in C# once, but I don’t remember any of it, so... no hints from me
Uh, “weird”? :) In what way are they “weird”? :)
12:40 AM
@AlexA. Those quotes are beautiful. &ldquo; and &rdquo;
@PhiNotPi let's say I want to do factorial
Hah! I did it with factorial too, back then :)
@Timwi They're all... slanty.
@CᴏɴᴏʀO'Bʀɪᴇɴ Incorrect
def f(n): return 1 if n == 1 else n*f(n-1)
sure
12:41 AM
@Timwi Something like this?
now, obviously this is not using lambda functions, and assigns to a variable f
@AlexA.: Yes, correct quotation marks are usually slanted. That’s completely normal. :)
but here's the thing
I can write this lambda function:
lambda n, f: 1 if n == 1 else n*f(n-1)
12:43 AM
then, I can write this lambda function lambda f: f(10, f)
@PhiNotPi what would (lambda f: f(10, f))(lambda n, f: 1 if n == 1 else n*f(n-1)) return?
err
A black hole
one mistake
the first function should be
lambda n, f: 1 if n == 1 else n*f(n-1, f)
and combined function thus becomes
(lambda f: f(10, f))(lambda n, f: 1 if n == 1 else n*f(n-1, f))
@PhiNotPi following it so far?
The only thing I've learned is that I know less about lambdas than I thought I did.
@PhiNotPi the trick here is first-order functions
okay, I got it now
12:50 AM
woops
I couldn't connect to the chat server
(My wifi is really bad)
no its not you
I had the same thing, but could connect to other sites
Those two things are not mutually exclusive.
fair enough
@PhiNotPi ok, so now we have an expression that computes the factorial of 10
okay
12:52 AM
all we have to do now, is make a function out of it
the final part is really easy :)
lambda N: (lambda f: f(N, f))(lambda n, f: 1 if n == 1 else n*f(n-1, f))
okay, neat
and that, is a recursive function, without named functions :)
Wow, my program insta-crashes Perl's interpreter.
@PhiNotPi you can go deeper however
@PhiNotPi in the lambda calculus (on which unnamed functions are based), you can only have one argument for each lambda function
@PhiNotPi so, let's say I want to write a function that multiplies two values
(lambda a, b: a*b)(3, 7)
Is this going to be currying?
12:55 AM
@Timwi shhhh
Sorry, I’m just asking
that works, but uses two variables passed into one function
(lambda a: (lambda b: a*b))(3)(7)
?
good!
almost
@PhiNotPi try and run it :)
small error
It might take a while to install Python.
12:57 AM
In [67]: (lambda a: (lambda b: a*b))(3, 7)
TypeError: <lambda>() takes 1 positional argument but 2 were given
<lambda>() takes 1 positional argument but 2 were given
there?
that's right :)
@PhiNotPi now apply that same thing to our factorial function:
lambda N: (lambda f: f(N, f))(lambda n, f: 1 if n == 1 else n*f(n-1, f))
@AlexA. Thanks.
@PhiNotPi one minor gripe by the way
no need for the inner parenthesis
(lambda a: lambda b: a*b)(3)(7)
1:00 AM
In the meantime, I've come up with a really good way to avoid my earlier problem.
@PhiNotPi is it working?
making everything into single arguments?
How do I get that lambda to run on the site Alex mentioned?
Copy and paste into the REPL
okay, I just had some parenthesis not copy-pasted
No, I don't know how to curry it.
1:09 AM
@PhiNotPi done?
oh ok
ok, I'll repeat the same thing here:
lambda N: (lambda f: f(N, f))(lambda n, f: 1 if n == 1 else n*f(n-1, f))
there's two places where we're calling f: on the left and on the right
so f(N, f) should become f(N)(f)
then, we must change lambda n, f: to lambda n: lambda f:
^ This is how you curry it
@PhiNotPi does that help?
lambda N: (lambda f: f(N)(f))(lambda n: lambda f: 1 if n == 1 else n*f(n-1)(f))
leave off the print
that's just for debugging
same for the call
good!
@PhiNotPi there is a little nugget of beauty and simplicity that's still being hidden here, however
@PhiNotPi swap the order of the N and f arguments
(in a new line, not edited)
lambda N: (lambda f: f(f)(N))(lambda f: lambda n: 1 if n == 1 else n*f(f)(n-1)) ?
1:18 AM
correct
now, let's say you were golfing
and let's ignore the last part of the lambda
is there a shorter way to write this?
lambda N: lambda f: f(f)(N)
to make it easier, let's change the middle part too
Not sure, but the f(f) feels highly redundant.
lambda N: BLA(N)
is there a shorter way to write that?
@PhiNotPi remember, BLA is a function
maybe I need to make it a bit less abstract
Just leave off the lambda N, so BLA(N) ?
@PhiNotPi almost
lambda N: BLA(N) is an expression that's a function
BLA(N) is a value that you get from calling BLA
@PhiNotPi can you simplify this? print((lambda N: math.factorial(N))(10))
Other than the print(math.factorial(10)) not sure.
1:26 AM
exactly!
(lambda N: math.factorial(N)) simply is math.factorial
remember, functions are values too!
(note math.factorial, not math.factorial(N))
math.factorial is a function
What is N.B.?
No brainer?
math.factorial(N) is a number that is the factorial of N
Not Butter?
1:27 AM
@AlexA. nota bene
Not a Bean?
Nota bene. Please excuse my Latin. :-p
What's it mean?
“Not a Bean” is shockingly close :-D
It means “please note”.
@PhiNotPi so, what is lambda N: BLA(N)?
1:28 AM
BLA
correct
so, what is lambda N: lambda f: f(f)(N)?
lambda f: f(f)
yes!
so, can you now simplify this?
lambda N: (lambda f: f(f)(N))(lambda f: lambda n: 1 if n == 1 else n*f(f)(n-1))
Could you just leave off the whole first part?
not quite
1:31 AM
Think about exactly which parts of (lambda N: math.factorial(N))(10) you removed and which stayed
well, I'm not sure what to make of (lambda f: f(f))(lambda f: lambda n: 1 if n == 1 else n*f(f)(n-1))
but that's it!
@PhiNotPi if f(f)(N) is the factorial of N, then that makes f(f)...?
I would assume the factorial function.
correct
do you understand it now?
that whole expression above is the factorial function
(lambda f: f(f))(lambda f: lambda n: 1 if n == 1 else n*f(f)(n-1))(10) would be the factorial of 10
How not to golf in Python
1:35 AM
# You can put it in a variable :)
factorial = (lambda f: f(f))(lambda f: lambda n: 1 if n == 1 else n*f(f)(n-1))
factorial_of_10 = factorial(10)
OK not sure why the backticks don’t work now
@Timwi press the 'fixed font' button to the right of send/upload
it's for
multiline messages
Backticks don't work on multi-lined chat messages.
@Timwi Inline formatting doesn't work in multiline messages
Oof, ninja'd
Apparently nor does the “fixed font” thing. It only works if you want to fix-font the whole message...
@Timwi ah yes
@PhiNotPi but now we can see a pattern
1:38 AM
Kinda weird. Why wouldn’t they have it support Markdown? We are on StackExchange, after all
@Timwi Chat supports a subset of markdown. Enough to make users everyone but Timwi happy but not enough to make the devs want to kill everything.
(lambda f: f(f))(lambda f: ___________________)
@AlexA.: I’m not happy ;-)
(and I’m a user, if it wasn’t clear :) )
Better?
@PhiNotPi whatever is in the expression ___________, it can be a recursive function by simply calling f(f) instead of f
1:40 AM
lambda f: f(f))(lambda f: f(f))     # StackOverflow
@Timwi nope
Yeah, no :)
(lambda f: f(f))(lambda f: f(f)())     # StackOverflow now? :)
actually
hrm, your first version was stack overflow
The first one is unmatched ) parens :P
yeah, but after fixing that
actually, no, yeah, that was a perfectly fine SO
I got thrown off
1:43 AM
I’m off to bed, I should have left hours ago
(lambda f: f(f))(lambda f: f(f)) is the same as def f(): f()
You guys are too interesting
Then how would you express def f(): f ?
@Timwi NOT ME! :D
My job is to troll moderate.
Well right now, I’m a little more than just “moderately” entertained
(lambda f: f)(lambda f: f)
1:45 AM
You cheated, you changed the first part
That’s just the same as lambda f: f
@Timwi the problem here is that you have made a 0 argument function, which doesn't exist in lambda calculus
(lambda f: f(f))(lambda f: lambda: None)
Ooooh good point
@Timwi on top of that def f(): f returns nothing :)
OK really off now
Well I don’t know the details of Python semantics, but you know what I mean by def f(): f
1:48 AM
@PhiNotPi as an excercise, using the pattern (lambda f: f(f))(lambda f: ___________________), can you now write a function that takes a list of integers, and returns their sum?
@Timwi def f(): return f
Then surely you should have written def f(): return f() in chat.stackexchange.com/transcript/message/23995847#23995847, even if it makes no difference to the stack overflow :)
@Timwi yeah my bad
Please turn off this chat, otherwise I won’t be able to go to bed
@PhiNotPi (and using only l[0] and l[1:] to index)
Right now I’m too tempted to actually write that integer sum function (but in C#)
1:51 AM
@Timwi what?
you're not done yet? :P
I am in my head...
I’m resisting the urge of going any further than that
@Timwi I can freeze the chat room but I think my fellow mods would be pissed
As well as everyone else
Sigh. Then I guess I’ll have to stay up the whole night
I mean the remaining half of the night
Do it.
I have to be somewhere in 11 hours!
1:52 AM
Irrelevant.
@Timwi make it come to you!
I can’t, I don’t have a piano.
def appointment(there): return here
Byebye.
zzzzzzzzzzzzzz
Spend the next 11 hours manufacturing a piano out of things in your house.
(that actually sounds pretty fun)
2:02 AM
"Hey Honey, why's there a hole in the wall?" "Sorry love, had to borrow some wood for the piano project"
Haha exactly! :D
@PhiNotPi seems like you have died and/or are gone, either way, what I just explained to you (in googlable terms) is the Y combinator, currying, and part of the lambda calculus
okay
the beauty of it is that since you can write recursion using single-argument lambdas, you've shown that single-argument lambdas are turing complete :)
I'm working on vector calc homework, and some other stuff
2:14 AM
I showed you a picture of panang curry
That's all you need
@ChrisJester-Young I have a fun fact
if, or cond, or whatever your conditional evaluation might look like in your language is not necessarily a primitive (or in lisp, a special form), and can be derived from other constructs
@orlp Well, at the base of it, one of if, cond, or and is required.
@ChrisJester-Young wrong
Or, hash table with boolean as key, lambdas as values.
(defun true (then else) then)
(defun false (then else) else)
2:21 AM
No, in Scheme that is not valid.
Booleans are supposed to be disjoint from procedures.
in the same way that Church numerals are not a valid implementation of numbers in a standard-compliant Scheme.
@ChrisJester-Young that's a choice though, I never said scheme specifically
Fine, but you know me, I think about everything from a Scheme perspective.
@ChrisJester-Young a simple indexed array as primitive would be enough too
How would you convert a boolean into an index?
without using if, that is.
You'd still need a hash table.
Then you may as well make a boolean->procedure hash table.
@ChrisJester-Young I was thinking 0 = false 1 = true
in general, all you need is any mapping from two distinct values you call true and false using primitives to two procedures
2:25 AM
Well, because of disjointness of types (again with Scheme), booleans aren't implicitly convertible to fixnums.
for example, in Python [lambda a, b: b, lambda a, b: a][True]
since True == 1
Again, I'm still thinking from a Scheme perspective.
@ChrisJester-Young I'm talking on a more fundamental level than scheme
the idea that conditional evaluation is not necessarily an axiom is a powerful idea
you might choose other axioms that are mutually exclusive with a non-axiomatic conditional
but that doesn't change the fact that there are legitimate systems in which if does not have to be axiomatic
I'm happy to do non-axiomatic conditionals; like I said, you can use a hashtable lookup in Scheme.
Anyway, it's an interesting implementation idea.
Maybe I'll toy with it a little.
(I've been meaning to write an R7RS implementation in C++11 for a while.)
@ChrisJester-Young even without the hash table lookup
the beauty of it
is that simply by saying
(defun true (then else) then)
(defun false (then else) else)
I can now implement algorithms expressed using conditionals, without ever using a special form for it
@BetaDecay i did it. i wrote your cake program
that might not correspond to the true/false that the language has chosen to be 'official', but that's irrelevant
2:31 AM
but at what cost
@undergroundmonorail since this is programming golf, I presume minimal cost
great cost to my own sanity, and also i might have summoned a lovecraftian horror by mistake
@undergroundmonorail Codethulhu?
@orlp Sure, that's like "Church booleans" (to extrapolate from Church numerals).
it's probably not a good sign for the language i designed if i, the person who understands it the best in the world almost certainly, write programs in it and then throw my hands in the air saying "it works and i don't know how but i'm done touching it"
@ChrisJester-Young exactly, that was the fun fact :P
2:35 AM
:-D
@ChrisJester-Young I've been implementing my own scheme too
mostly done with garbage collection
@orlp Apparently, Church boolean is a real term.
In mathematics, Church encoding is a means of representing data and operators in the lambda calculus. The data and operators form a mathematical structure which is embedded in the lambda calculus. The Church numerals are a representation of the natural numbers using lambda notation. The method is named for Alonzo Church, who first encoded data in the lambda calculus this way. Terms that are usually considered primitive in other notations (such as integers, booleans, pairs, lists, and tagged unions) are mapped to higher-order functions under Church encoding. The Church-Turing thesis asserts that...
IIRC there was something I fundamentally disagreed with with the official scheme spec
but I can't remember :(
@orlp Too bad, because I'd be curious to hear.
@ChrisJester-Young well, here we go again... trac.sacrideo.us/wg/raw-attachment/wiki/WikiStart/r7rs.pdf
2:39 AM
@orlp GC, hygienic macros, and continuations are probably the 3 hardest things to implement in a Scheme implementation.
@ChrisJester-Young I wasn't entirely done yet, but I think I had nailed GC
obviously not the most optimized insane thing, but it was a compacting moving stop-the-world GC
Nice (or at least nicer than conservative GCs), but I'm fascinated by the parallel GCs that the JVM has....
@ChrisJester-Young I fundamentally disagree with the JVM =/
if people shipped something the equivalent of LLVM IIR, you could do the same thing, native
@orlp Do you disagree with JVM because it's a managed execution environment? Or something else?
@ChrisJester-Young I disagree with virtualizing the CPU
2:43 AM
@orlp It doesn't virtualise the CPU though. It runs natively, with the aid of a JIT compiler.
If I get lambdas to work in my language as I think they will, it will be most terrific.
@ChrisJester-Young that's an optimization of the virtualization :)
"terrific" defined as "terror-inducing"
@orlp In the 90s, you could think that way. But in this millennium, I don't think anybody thinks of the JVM as an interpretation-based system.
lambda l,o,v,e,c,r,a,f,t:'he comes'
2:45 AM
12 mins ago, by Chris Jester-Young
@undergroundmonorail Codethulhu?
@ChrisJester-Young the thing is, JIT has its place, but not when ahead-of-time could do the exact same thing
I wouldn't mind JIT'ing stuff to get faster workflows while in development
(just like running with -O0)
See, the only downside of JIT is the warmup cost. But there are some optimisations that are JIT-only and cannot be done by AOT.
Profile-guided optimisation, for example.
@ChrisJester-Young that's not true
you can do profile-guided opt AOT
Can it dynamically adapt the optimisation strategy based on the current workload?
Because, the JVM in Java 6+ does that.
@ChrisJester-Young no, but I'd argue such workloads are exceedingly rare, and if they exist you can detect and program for them
2:50 AM
Why should the programmer be burdened with programming for them, though?
when the runtime can Do The Right Thing for you?
@ChrisJester-Young because the runtime can't do that
the runtime Can Randomly Make Your Program Slower In The Hope It Stumbles Upon An Optimization
So the runtime keeps statistics and optimises for the "happy path" (the common case, as detected by statistics).
@ChrisJester-Young detection is very expensive
There's still a deoptimised version for unhappy paths.
so is statistics
and so is optimization
if possible, you want to load it to compile time
2:52 AM
I would say that the costs of such things are amortised by the performance gains you get.
Maybe I have drunk the John Rose Kool-Aid, but I'm a huge believer of JIT.
@ChrisJester-Young clearly they're not, otherwise Java should beat C / C++ on a more regular basis than carefully constructed examples
In related news, I want to try to make a Scheme implementation that is as performant as C++, but I know that's a long shot.
@ChrisJester-Young I believe JIT can be a viable strategy in some niche cases (like really extreme workloads with lots of 'happy paths'), but I believe the default should be AOT, with JIT available on request by the user
Certainly, the .NET designers agree with you, because every time you install a new assembly, ngen gets run....

« first day (1685 days earlier)      last day (3322 days later) »