Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #14726

Re: Warsaw Univ. course, was Re: Work on Basic

From Leonid Shifrin <lshifr@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Warsaw Univ. course, was Re: Work on Basic
Date 2013-06-04 03:12 +0000
Message-ID <kojlva$kas$1@smc.vnet.net> (permalink)
References <kmngb2$3rv$1@smc.vnet.net>
Organization Time-Warner Telecom

Show all headers | View raw


On Tue, Jun 4, 2013 at 12:45 AM, Richard Fateman
<fateman@eecs.berkeley.edu>wrote:

> On 6/3/2013 9:25 AM, Leonid Shifrin wrote:
>
> <long message>
>
> Thanks for what I consider a most agreeable contribution.
> I was not aware of your material on stackexchange, which seems
> to be rather nice.
>

Thanks, I do appreciate your opinion.


>
>
> You are right that my example regarding mutable Lists in Mathematica
> was incorrect. Actually on two grounds.  The syntax was not right and
> I did not mean to say that Lists in Mathematica are not mutable, since
> they certainly are.
>
> Just that Lists have the uncomfortable property that if you access one
> element,
> all the others are re-evaluated. Here is an example, which I think is free
> of
> mis-used syntax...
>
> (   q=Table[f[i],{i,1,3}];
>      f[n_]:=(Print[n];g[n]))
>
> q[[2]]
>
>     evaluates to display
> 1
> 2
> 3
> g[2]
>
> Changing q by, for example,   q[[2]]=hello
> does not re-evaluate the elements.
> However, referring to in again as q[[2]] does this:
> 1
> 3
> hello
>


Yes, this is indeed what happens. Arguably this is a correct behavior
(for Mathematica), because Mathematica can not tell in advance that
q will not evaluate to something else. For example, we could have q
assigned to some other symbol, and that symbol to hold the list.

In general, this is because Part does not hold its arguments. Given that
Part works on general expressions, I don't find this inconsistent.
If you don't want this behavior, one way out is to not store the values in
a list, but rather store them in some head which holds their elements,
such as Hold:

In[5]:= q1 = Map[f, Hold @@ Range[3]]

Out[5]= Hold[f[1], f[2], f[3]]

In this case, we get


In[6]:= q1[[2]]

During evaluation of In[6]:= 2

Out[6]= g[2]

Which seems to be the behavior you expected. One could
use HoldComplete in place of Hold, which would arguably
be even better since that would have prevented any non-trivial
evaluation of q1 whasoever (including e.g. search for UpValues,
not prevented by Hold).


Regards,
Leonid




>
> Thanks for pointing out the original error.
> RJF
>
>
>

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Work on Basic Mathematica Stephen! "djmpark" <djmpark@comcast.net> - 2013-05-12 07:28 +0000
  Re: Work on Basic Mathematica Stephen! psycho_dad <s.nesseris@gmail.com> - 2013-05-13 07:47 +0000
  Re: Work on Basic Mathematica Stephen! psycho_dad <s.nesseris@gmail.com> - 2013-05-13 09:40 +0000
  Re: Work on Basic Mathematica Stephen! "Nasser M. Abbasi" <nma@12000.org> - 2013-05-14 07:14 +0000
  Re: Work on Basic Mathematica Stephen! Szabolcs Horvát <szhorvat@gmail.com> - 2013-05-15 06:54 +0000
  Re: Work on Basic Mathematica Stephen! Szabolcs Horvát <szhorvat@gmail.com> - 2013-05-16 07:28 +0000
  Re: Work on Basic Mathematica Stephen! Peter Klamser <klamser@googlemail.com> - 2013-05-16 07:28 +0000
  Re: Work on Basic Mathematica Stephen! Andrzej Kozlowski <akozlowski@gmail.com> - 2013-05-17 08:34 +0000
  Re: Work on Basic Mathematica Stephen! Murray Eisenberg <murray@math.umass.edu> - 2013-05-17 08:34 +0000
  Re: Work on Basic Mathematica Stephen! Peter Klamser <klamser@googlemail.com> - 2013-05-17 08:34 +0000
  Re: Work on Basic Mathematica Stephen! Andrzej Kozlowski <akozlowski@gmail.com> - 2013-05-18 06:38 +0000
  Re: Work on Basic Mathematica Stephen! Peter Klamser <klamser@googlemail.com> - 2013-05-18 06:37 +0000
  Re: Work on Basic Mathematica Stephen! Murray Eisenberg <murray@math.umass.edu> - 2013-05-19 09:46 +0000
  Re: Work on Basic Mathematica Stephen! paulmchale7@gmail.com - 2013-05-19 09:47 +0000
  Re: Work on Basic Mathematica Stephen! paulmchale7@gmail.com - 2013-05-19 09:47 +0000
    Re: Work on Basic Mathematica Stephen! Szabolcs Horvát <szhorvat@gmail.com> - 2013-05-23 07:51 +0000
    Re: Work on Basic Mathematica Stephen! "djmpark" <djmpark@comcast.net> - 2013-05-24 09:26 +0000
  Re: Work on Basic Mathematica Stephen! ?iso-8859-1?Q?J=E1nos_L=F6bb?= <janos@lobb.com> - 2013-05-19 09:47 +0000
  Re: Work on Basic Mathematica Stephen! Andrzej Kozlowski <akozlowski@gmail.com> - 2013-05-20 09:03 +0000
  Re: Work on Basic Mathematica Stephen! Andrzej Kozlowski <akozlowski@gmail.com> - 2013-05-20 09:03 +0000
  Re: Work on Basic Mathematica Stephen! "Ernst H.K. Stelzer" <ernst.stelzer@physikalischebiologie.de> - 2013-05-20 09:03 +0000
  Re: Work on Basic Mathematica Stephen! Ingolf Dahl <ingolf.dahl@telia.com> - 2013-05-20 09:03 +0000
  Re: Work on Basic Mathematica Stephen! David Annetts <david.annetts@iinet.net.au> - 2013-05-20 09:03 +0000
  Re: Work on Basic Mathematica Stephen! "mathgroup " <fizzymath@knology.net> - 2013-05-22 06:18 +0000
    expanding the use of symbolic computation in engineering .. was Re: Richard Fateman <fateman@cs.berkeley.edu> - 2013-05-23 07:51 +0000
    Re: expanding the use of symbolic computation in engineering .. was Re: W Craig Carter <ccarter@MIT.EDU> - 2013-05-24 09:23 +0000
  Re: Work on Basic Mathematica Stephen! "djmpark" <djmpark@comcast.net> - 2013-05-23 07:54 +0000
  Re: Work on Basic Mathematica Stephen! "mathgroup " <fizzymath@knology.net> - 2013-05-23 07:56 +0000
    Re: Work on Basic Mathematica Stephen! Richard Fateman <fateman@cs.berkeley.edu> - 2013-05-24 09:27 +0000
    Re: Work on Basic Mathematica Stephen! "djmpark" <djmpark@comcast.net> - 2013-05-25 09:35 +0000
    Re: Work on Basic Mathematica Stephen! Richard Fateman <fateman@eecs.berkeley.edu> - 2013-05-25 09:35 +0000
    Re: Work on Basic Mathematica Stephen! "djmpark" <djmpark@comcast.net> - 2013-05-25 09:35 +0000
  Re: Work on Basic Mathematica Stephen! "mathgroup " <fizzymath@knology.net> - 2013-05-24 09:28 +0000
  Re: Work on Basic Mathematica Stephen! Murray Eisenberg <murray@math.umass.edu> - 2013-05-24 09:23 +0000
  Re: Work on Basic Mathematica Stephen! "djmpark" <djmpark@comcast.net> - 2013-05-24 09:26 +0000
  Re: Work on Basic Mathematica Stephen! Andrzej Kozlowski <akozlowski@gmail.com> - 2013-05-25 09:34 +0000
    Warsaw Univ. course,  was Re: Work on Basic Mathematica Stephen! Richard Fateman <fateman@cs.berkeley.edu> - 2013-05-26 08:38 +0000
    more problems in Warsaw plan? Re: Work on Basic Mathematica Stephen! Richard Fateman <fateman@cs.berkeley.edu> - 2013-05-26 08:36 +0000
    Re: Work on Basic Mathematica Stephen! David Bailey <dave@removedbailey.co.uk> - 2013-05-28 07:47 +0000
  Re: Work on Basic Mathematica Stephen! John Doty <noqsiaerospace@gmail.com> - 2013-05-27 08:21 +0000
    Re: Work on Basic Mathematica Stephen! David Bailey <dave@removedbailey.co.uk> - 2013-06-02 04:24 +0000
  Re: Warsaw Univ. course,  was Re: Work on Basic Mathematica Stephen! John Doty <noqsiaerospace@gmail.com> - 2013-05-27 08:21 +0000
    Re: Warsaw Univ. course,  was Re: Work on Basic Mathematica Stephen! Richard Fateman <fateman@cs.berkeley.edu> - 2013-05-28 07:49 +0000
      Re: Warsaw Univ. course,  was Re: Work on Basic Mathematica Stephen! David Bailey <dave@removedbailey.co.uk> - 2013-05-31 07:19 +0000
        Re: Warsaw Univ. course,  was Re: Work on Basic Mathematica Stephen! Richard Fateman <fateman@cs.berkeley.edu> - 2013-06-01 10:06 +0000
          Re: Warsaw Univ. course,  was Re: Work on Basic Mathematica Stephen! David Bailey <dave@removedbailey.co.uk> - 2013-06-02 04:22 +0000
            Re: Warsaw Univ. course,  was Re: Work on Basic Mathematica Stephen! Richard Fateman <fateman@cs.berkeley.edu> - 2013-06-03 07:25 +0000
              Re: Warsaw Univ. course,  was Re: Work on Basic Mathematica Stephen! David Bailey <dave@removedbailey.co.uk> - 2013-06-04 03:14 +0000
              Re: Warsaw Univ. course,  was Re: Work on Basic Mathematica Stephen! Andrzej Kozlowski <akozlowski@gmail.com> - 2013-06-04 09:59 +0000
        Re: Warsaw Univ. course, was Re: Work on Basic Mathematica Richard Fateman <fateman@eecs.berkeley.edu> - 2013-06-04 03:15 +0000
  Re: Warsaw Univ. course,  was Re: Work on Basic Mathematica Stephen! Ingolf Dahl <ingolf.dahl@telia.com> - 2013-05-27 08:21 +0000
  Re: Work on Basic Mathematica Stephen! fd <fdimer@gmail.com> - 2013-05-28 07:46 +0000
    Re: Work on Basic Mathematica Stephen! David Bailey <dave@removedbailey.co.uk> - 2013-05-31 07:19 +0000
  Re: Work on Basic Mathematica Stephen! fd <felipe.dimer-de-oliveira@mq.edu.au> - 2013-05-28 07:47 +0000
  Re: Warsaw Univ. course,  was Re: Work on Basic Mathematica Stephen! fd <fdimer@gmail.com> - 2013-05-29 07:47 +0000
  Re: Warsaw Univ. course,  was Re: Work on Basic Mathematica Stephen! Andrzej Kozlowski <akozlowski@gmail.com> - 2013-05-29 07:48 +0000
  Re: Warsaw Univ. course,  was Re: Work on Basic Mathematica Stephen! János Löbb <janos@lobb.com> - 2013-05-30 10:07 +0000
    Re: Warsaw Univ. course,  was Re: Work on Basic Mathematica Stephen! "Nasser M. Abbasi" <nma@12000.org> - 2013-05-31 07:15 +0000
  Re: Warsaw Univ. course,  was Re: Work on Basic Mathematica Stephen! Murray Eisenberg <murray@math.umass.edu> - 2013-05-30 10:08 +0000
  Applying Mathematica to practical problems John Doty <noqsiaerospace@gmail.com> - 2013-05-30 10:09 +0000
    Re: Applying Mathematica to practical problems Richard Fateman <fateman@cs.berkeley.edu> - 2013-05-31 07:15 +0000
    Re: Applying Mathematica to practical problems "Kevin J. McCann" <kjm@KevinMcCann.com> - 2013-05-31 07:18 +0000
  Re: Applying Mathematica to practical problems Andrzej Kozlowski <akozlowski@gmail.com> - 2013-05-31 07:16 +0000
    Re: Applying Mathematica to practical problems Richard Fateman <fateman@cs.berkeley.edu> - 2013-06-01 10:07 +0000
    Re: Applying Mathematica to practical problems Richard Fateman <fateman@cs.berkeley.edu> - 2013-06-01 10:07 +0000
    Re: Applying Mathematica to practical problems Andrzej Kozlowski <akozlowski@gmail.com> - 2013-06-02 04:23 +0000
      Re: Applying Mathematica to practical problems Richard Fateman <fateman@cs.berkeley.edu> - 2013-06-03 07:24 +0000
      Re: Applying Mathematica to practical problems Andrzej Kozlowski <akozlowski@gmail.com> - 2013-06-04 03:11 +0000
      Re: Applying Mathematica to practical problems Andrzej Kozlowski <akozlowski@gmail.com> - 2013-06-04 03:11 +0000
      Re: Applying Mathematica to practical problems Richard Fateman <fateman@eecs.berkeley.edu> - 2013-06-04 03:10 +0000
      Re: Applying Mathematica to practical problems Andrzej Kozlowski <akozlowski@gmail.com> - 2013-06-04 03:11 +0000
      Re: Applying Mathematica to practical problems Andrzej Kozlowski <akozlowski@gmail.com> - 2013-06-04 03:13 +0000
  Mathematica numerics and... Re: Applying Mathematica to practical problems Daniel Lichtblau <danl@wolfram.com> - 2013-06-01 10:06 +0000
    Interval vs default,  was Re: Mathematica numerics and... Re: Applying Richard Fateman <fateman@cs.berkeley.edu> - 2013-06-02 04:24 +0000
  Re: Applying Mathematica to practical problems Andrzej Kozlowski <akozlowski@gmail.com> - 2013-06-02 04:23 +0000
  Re: Applying Mathematica to practical problems James Stein <mathgroup@stein.org> - 2013-06-02 04:26 +0000
  Re: Applying Mathematica to practical problems Mark McClure <mcmcclur@unca.edu> - 2013-06-02 04:23 +0000
    Re: Applying Mathematica to practical problems Richard Fateman <fateman@cs.berkeley.edu> - 2013-06-03 07:25 +0000
    Re: Applying Mathematica to practical problems Joe Gwinn <joegwinn@comcast.net> - 2013-06-03 07:26 +0000
  Re: Applying Mathematica to practical problems Waclaw Kusnierczyk <waku@idi.ntnu.no> - 2013-06-03 07:24 +0000
  Re: Warsaw Univ. course, was Re: Work on Basic Leonid Shifrin <lshifr@gmail.com> - 2013-06-04 03:12 +0000
  Re: Warsaw Univ. course, was Re: Work on Basic Leonid Shifrin <lshifr@gmail.com> - 2013-06-04 03:13 +0000
  Re: Interval vs default, was Re: Mathematica numerics and... Re: Applying Daniel Lichtblau <danl@wolfram.com> - 2013-06-04 03:14 +0000

csiph-web