News for hackers. Stuff that matters.

muflax

Re:Ask HN: What are the cool life hacks for Developer? on Friday August 12, 2016 @12:31PM (#12276921)
How do you discover problems that regular people have?

Especially because what most businesses actually do on a daily basis, and what annoying problems they have, is totally invisible to me.

Re:Rustls: new, modern TLS library written in Rust on Sunday July 10, 2016 @10:07AM (#12065607)
Perl is explicitly postmodern. Here's Larry Wall explaining it: http://www.wall.org/~larry/pm.html
Re:Why didn't Common Lisp fix the world? on Thursday May 19, 2016 @01:23PM (#11731858)
Thanks! I vaguely remembered there being some problems with that, but playing around with it, it works fine and as I'd expect. Sweet! Gotta revisit CL soon then.
Re:Why didn't Common Lisp fix the world? on Tuesday May 17, 2016 @01:36PM (#11715580)
How does static type checking work in CL?

One of the most important use cases for static typing is safe modification of existing code, like during refactoring. So a typical example: I have some struct with a field of one type, say a string. I use it in a few functions, reading and writing it. Now I change the field to a different type, say an array of strings instead. I want the compiler to tell me about all the code that's now invalid. How do I do that?

I quickly wrote up a simple example of the (statically) untyped code I mentioned: http://pastebin.com/f7KWETvT (I can also write a matching example in some common static language (like C or ML), but I think it's clear what I mean.)

What type annotations do I add to make that basic use case work? So what do I add such that it first type-checks when name is just a string, then change the annotation to make name an array of strings, and get two compile-time errors because the functions are now wrong.

(Unfortunately, I only know a little bit of CL (and even then mostly due to familiarity with Emacs Lisp), so my example might be a bit un-idiomatic. Feel free to turn it into idiomatic CL if something is too weird!)

How does PHP have dynamic scope? It's been ages since I touched it, but if I remember right...

Global is just a flat namespace. Functions have their own, separate flat namespace each. I tried the following in a REPL:

function two() { echo $a; }

function one() { $a = 1; two(); }

one();

as the standard dynamic scope example, and I get an "undefined variable" error. Did that use to be dynamic? (I wouldn't be surprised, though, especially given PHP's implementation history...)

There is an explicit "static" modifier that looks dynamic, but I couldn't get it to run that way. It seems to just retain state in recursive calls of the same function, or something?

[edit:] (And PHP doesn't predate Javascript, but regardless, "no first-class functions" isn't "no lexical scope".)

What languages without lexical scope are you thinking of?

Aside from literally only (pre-Common and Emacs) Lisp, I can't think of any language without lexical scope (outside some constructs etc).

[edit:] Or are you thinking of "only a single global namespace"? Even that exists only in otherwise highly restricted scripting languages, I think? ("Everything global" is technically lexical, but I see why you wouldn't want to call it that.)

Re:The Problem with Friendly C on Saturday December 26, 2015 @03:18AM (#10793654)
Which ones?