all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Check for redundancy
Date: Fri, 03 Jul 2015 10:40:55 +0200	[thread overview]
Message-ID: <87si95iqg8.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: mailman.6209.1435880273.904.help-gnu-emacs@gnu.org

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	other threads:[~2015-07-03  8:40 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.6209.1435880273.904.help-gnu-emacs@gnu.org>
2015-07-03  8:40 ` Pascal J. Bourguignon [this message]
2015-07-03 20:04   ` Check for redundancy Emanuel Berg
2015-06-24  9:29 Andreas Röhler
2015-06-24 13:23 ` Drew Adams
2015-06-24 14:55   ` Andreas Röhler
     [not found]   ` <mailman.5580.1435157733.904.help-gnu-emacs@gnu.org>
2015-06-24 18:21     ` Stefan Monnier
2015-06-24 21:10       ` tomas
2015-06-25  3:23         ` Stefan Monnier
2015-06-25  7:47           ` tomas
2015-06-26 15:01             ` Emanuel Berg
2015-06-26 20:25               ` Marcin Borkowski
2015-06-26 22:48                 ` Emanuel Berg
2015-06-27 12:11                 ` Robert Thorpe
2015-06-27 13:12                   ` tomas
2015-06-27 23:02                     ` Emanuel Berg
2015-06-28 11:07                       ` tomas
2015-06-28 15:50                         ` Emanuel Berg
2015-06-28 16:35                           ` Yuri Khan
2015-06-28 20:03                             ` Emanuel Berg
2015-06-28 21:38                           ` Robert Thorpe
2015-06-28 23:47                             ` Emanuel Berg
2015-07-02 23:37                               ` Robert Thorpe
2015-07-03  3:36                                 ` Yuri Khan
2015-07-03  6:41                                   ` Eli Zaretskii
2015-07-03 11:48                                     ` Yuri Khan
2015-07-03 12:16                                       ` Eli Zaretskii
2015-07-03 22:59                                         ` Robert Thorpe
2015-07-03  6:09                                 ` tomas
2015-07-03 19:56                                   ` Emanuel Berg
     [not found]                                 ` <mailman.6215.1435903802.904.help-gnu-emacs@gnu.org>
2015-07-03  6:38                                   ` Rusi
2015-07-03  7:54                                     ` tomas
2015-07-03  8:55                                     ` Loris Bennett
2015-06-24 23:31       ` Emanuel Berg
2015-06-25  2:03       ` Óscar Fuentes
2015-06-25  2:07         ` Emanuel Berg
2015-06-25  2:53           ` Óscar Fuentes
2015-06-25  3:21             ` Emanuel Berg
     [not found]       ` <mailman.5603.1435188769.904.help-gnu-emacs@gnu.org>
2015-06-25  7:43         ` Stefan Nobis
2015-06-25  8:52           ` Andreas Röhler
2015-06-26 14:51             ` Emanuel Berg
2015-06-26 14:39           ` Emanuel Berg
     [not found]           ` <mailman.5719.1435329683.904.help-gnu-emacs@gnu.org>
2015-06-27  7:40             ` Stefan Nobis
2015-06-28  2:02               ` Emanuel Berg
2015-06-28  2:40                 ` Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87si95iqg8.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.