Re: Equality, Assignment and The Emperor's New Clothes
- From: Bruce Lewis <brlspam@xxxxxxxxx>
- Date: 23 Jan 2006 12:05:45 -0500
bobueland@xxxxxxxxx writes:
> In the introduction to R5RS the philosphy behind Scheme is stated
>
> "Programming languages should be designed not by piling feature on top
> of feature .."
I think they had a specific scenario or two in mind. Say a language has
two features that one might think could be combined so solve a
particular type of problem. Unfortunately, the features were designed
in a way that doesn't allow them to be combined. Rather than redesign
the basic features of the language so that they can work together,
suppose the language designers create a new feature to solve that same
problem.
Or say a language feature can be used in one context but not another.
The Scheme way of designing the language would be to replace it with
something that could work in either context.
This is all in the context of features that have to be designed into the
language. I don't think it applies to features that can be easily built
on top of existing features. For example, you could easily build the
various number comparators on top of < and boolean operators, but the
langauge includes >, =, <=, >= anyway. I don't see this as violating
the stated philosophy.
> However when I come to deciding if two object are equal I have to learn
> about
>
> eq? eqv? equal? and type specific like char=?, string=?, =, ..
>
> Many of these or not easy to understand. In R5RS, three pages or used
> just to explain eqv?.
R5RS is a good thing to read, but it is written for language
implementors who need to know the details. You could just always use
equal? and be happy for years. You might even find that your Scheme
implementation makes equal? terminate on recursive data structures.
If this terminates in your implementation you could write with equal?
your whole life:
(let ((x (list 'a))) (set-cdr! x x) (equal? x x))
Given how much faster computers are these days, my own feeling is that
equal? should be required to work on recursive structures just as list?
is. Implementors already have to do tortoise and hare for list?, why
not do it for equal? as well. Users /that/ concerned about performance
can write their own equivalence predicates.
For reading others' code, just know that eq? means same-object?. All
those other predicates are there to throw errors if the objects you're
comparing don't have the types you expect. Plus the whole case
sensitivity thing. You can go back and find them when you're doing
something where you get the feeling equal? isn't what you want.
> For declaring variables and assigning values to them several constructs
> are used
>
> define, let, let*, letrec, named let
>
> They are not easy to understand. To get some feeling for them you must
> translate them into underlying lambda expressions which are not so easy
> to analyze themeselves.
No you mustn't. Especially named let can be much better understood from
examples of its usage. Use define for globals and the rest for
limited-scope definitions. Even with the fuzziest idea of what the
various let forms do you can start coding. You can find the right form
with trial and error.
> Now people who wrote R5RS are smart, much smarter than me. How come
> that such difficult constructs are allowed for seemingly simple things.
> The complexity in assignment and equality test is *not* an a priori
> difficulty since they are not that hard to understand in other
> languages.
Or rather, they used to not be. Time was when PHP only had ==, same as
eqv? in Scheme. Then they realized that some objects are equaler than
others and came up with ===, which I believe works like eq? in Scheme.
They're so object-oriented these days that if they haven't already
realized people will want to do == recursively, they soon will, and
we'll have an equivalent of equal?, or maybe == will be made the same as
equal? and some old PHP code will break.
In C you have == being very much like Scheme's eq?, and lots of people
by the results they get when using it on strings. You have to know what
type of data you're comparing and use strcmp(), etc. There's no option
like eqv? to compare two objects without thinking about their types.
In short, equality tests in other languages are just as complicated,
because you still have to think about same-object tests vs type-specific
tests, and about whether you want to compare recursively.
For assignment, there's something you need to understand about the R5RS
authors. Yes, they're very smart. They are also obsessive about
hygiene. Little Johnny is not allowed to touch that variable unless he
knows where it comes from and who else might be touching it. He also
needs to be precise about how his own variables touch each other.
He must use let if his variables get their values from the outside
without depending on each other.
He must use let* if within his set of variables subsequent ones depend
on prior ones.
He must use letrec when defining mutually recursive functions.
Sometimes you can use the wrong let form and get away with it, just
don't let the R5RS authors catch you at it. Especially watch out for
that Will Clinger guy. ;-)
> If there are some people reading this who have discussed R5RS, have you
> the same feeling as I that this unneccessary complicated, or am I
> seeing ghosts in broad daylight?
>
> (I'm not saying that I have any good alternative, but when simple
> things in my own work start to get complicated I usually go back to the
> foundations themeselves and try to figure out the source of these
> difficulties).
More precisely, you try to figure out whether the complexity is inherent
in the problem you're trying to solve, or whether you've manufactured
the complexity yourself as you went along.
I think it's clear that the equivalence complexity is inherent in the
problem. Assignment might be somewhat debatable, but there have been
times when Scheme's hygiene has kept me out of trouble.
--
http://ourdoings.com/ Easily organize and disseminate news and
photos for your family or group.
.
- Follow-Ups:
- Re: Equality, Assignment and The Emperor's New Clothes
- From: Abdulaziz Ghuloum
- Re: Equality, Assignment and The Emperor's New Clothes
- From: Bruce Lewis
- Re: Equality, Assignment and The Emperor's New Clothes
- References:
- Equality, Assignment and The Emperor's New Clothes
- From: bobueland
- Equality, Assignment and The Emperor's New Clothes
- Prev by Date: Re: Equality, Assignment and The Emperor's New Clothes
- Next by Date: Piling feature on top of feature (was: Equality, Assignment and The Emperor's New Clothes)
- Previous by thread: Re: Equality, Assignment and The Emperor's New Clothes
- Next by thread: Re: Equality, Assignment and The Emperor's New Clothes
- Index(es):
Relevant Pages
|