help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Check for redundancy


From: Pascal J. Bourguignon
Subject: Re: Check for redundancy
Date: Fri, 03 Jul 2015 10:40:55 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Robert Thorpe <rt@robertthorpeconsulting.com> writes:

> Emanuel Berg <embe8573@student.uu.se> writes:
>
>> Robert Thorpe <rt@robertthorpeconsulting.com> writes:
>>> Just because there aren't types doesn't mean that
>>> variables don't have types. What "untyped" means is
>>> that the language doesn't enforce typing for you.
>>> That makes it more important that you manage them
>>> carefully for yourself.
>>
>> ... are you sure?
>>
>> In C, you do
>>
>>     int five = 5;
>>
>> In Lisp (Elisp), you do
>>
>>     (let ((five 5)) ...)
>
> I don't understand what this has to do with the issue.  Both of the
> languages here have types.  C has static types and Lisp has latent (or
> dynamic) types.

Yes.  And C is weakly typed, while Lisp is strongly typed:

      #include <stdio.h>
      int main(void){
        char a[]="hello"; 
        int b=a+3;
        printf("%d\n",b);
        return 0;
      }
      prints some random garbage such as: -1309384925
      status = 0
 
instead:

      (let* ((a "hello")
             (b (+ a 3)))
        b)
      Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p
                 "hello")

> What about assembly language?  What about other languages with no type
> system or a very limited type system?
>
>> If you want to, you can do (integerp five)
>
> In Lisp the type of a variable is stored with the variable at runtime.

No, never, ever, not in a billion years.

In lisp, types are not associated with variables, but with objects!

There's nothing in the definition of the lisp language that would
prevent this association to be performed at compilation time, in some
cases at least.

When in CL you declare a type naming a variable, what you are  telling
the computer, is that you promise you will never bind to that variable
objects of a different type.  But it's still the objects to which the
type is associated, the objects bound to that variable, not the
variable.


> In C the type of a variable is recorded and enforced at compile time.

Usually.  There's nothing in the C langage definition that prevents
run-time checks.  On the contrary, most type casting are undefined or
have implementation specific behaviors.  For example, check the
restrictions on using the variants of a union.



> In many Assembly languages neither are done.  You can't ask the variable
> what it's type is and you can't ask the compiler either.  The only
> record is in your program and in your mind.

Indeed, there are very few machines that associate type with the objects
(the values).  The only one coming to mind is the lisp machine
processor, but IIRC, there may have been a few other machines with type
tags.


>> However, the way I understood HN is that you should
>> *always* use prefixes like that. What I remembered it
>> looked like this:
>>
>>     intMoney = 0;
>>     strGreeting = "Stay a while, and listen!";
>>
>> And I don't see any reason to do that.
>
> It's useful in assembly language programming.
>
> It's also useful in MS Window programming where everything is some kind
> of handle.  Even then though, I would only use it for the user
> interface, not every variable as you say.

The programmer must control its data flows, and therefore he should have
an idea of what data goes into what variables and parameters.  

A tool useful for newbies is to control the type of those data flow,
since often in a single function,  you will have different types for
different data flows. 

However, assigning compilation-time types or using hungarian notation
has at least one big problem:  this prevent generic programming, by
constraining the types of your data much to early in general,

What if now money is represented by its own class associating the
currency with the amount, and if you live the USA, the origin of the
money along with the required documentation, less the cops forfeit it.
(So you see, it's very important to be able to switch to something of
another type, notably for some users).

    (defun invest (intMoney)
       …)

    (invest (make-money
             :amount 10000 :currency :USD 
             :origin (make-trace
                      :explaination "Got a good salary last month."
                      :source-name "My Employer Com"
                      :source-address "Beyond Infinity Drive, 42\nYunque Bajo, 
CA92222"
                      :document-url 
"http://my.employer.com/salaries/myself/2025/oct.xml";)))

    BANG! invest expected (why? for no reason!) an integer instead of
    some money.


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


reply via email to

[Prev in Thread] Current Thread [Next in Thread]