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


Groups > comp.lang.c > #77164 > unrolled thread

->=

Started byglen herrmannsfeldt <gah@ugcs.caltech.edu>
First post2015-11-25 14:53 +0000
Last post2015-11-28 14:59 -0500
Articles 6 on this page of 46 — 15 participants

Back to article view | Back to comp.lang.c


Contents

  ->= glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-25 14:53 +0000
    Re: ->= Richard Heathfield <rjh@cpax.org.uk> - 2015-11-25 15:12 +0000
      Re: ->= James Kuyper <jameskuyper@verizon.net> - 2015-11-25 11:51 -0500
        Re: ->= "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-25 09:49 -0800
        Re: ->= supercat@casperkitty.com - 2015-11-25 09:55 -0800
      Re: ->= John Bode <jfbode1029@gmail.com> - 2015-11-25 12:24 -0800
        Re: ->= James Kuyper <jameskuyper@verizon.net> - 2015-11-25 15:40 -0500
          Re: ->= John Bode <jfbode1029@gmail.com> - 2015-11-27 17:14 -0800
            Re: ->= James Kuyper <jameskuyper@verizon.net> - 2015-11-27 20:28 -0500
    Re: ->= "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-25 07:35 -0800
    Re: ->= "Charles Richmond" <numerist@aquaporin4.com> - 2015-11-25 15:47 -0600
      Re: ->= James Kuyper <jameskuyper@verizon.net> - 2015-11-25 17:04 -0500
      Re: ->= Nobody <nobody@nowhere.invalid> - 2015-11-26 10:58 +0000
        Re: ->= supercat@casperkitty.com - 2015-11-26 08:55 -0800
    Re: ->= raltbos@xs4all.nl (Richard Bos) - 2015-11-26 00:48 +0000
    Re: ->= Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-27 14:15 -0800
      Re: ->= supercat@casperkitty.com - 2015-11-27 14:26 -0800
        Re: ->= BartC <bc@freeuk.com> - 2015-11-27 23:38 +0000
          Re: ->= Keith Thompson <kst-u@mib.org> - 2015-11-27 19:37 -0800
            Re: ->= Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-28 06:35 -0800
        Re: ->= Stephen Sprunk <stephen@sprunk.org> - 2015-11-27 17:51 -0600
        Re: ->= Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-28 06:53 -0800
          Re: ->= glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-28 17:12 +0000
            Re: ->= Keith Thompson <kst-u@mib.org> - 2015-11-28 10:26 -0800
              Re: ->= glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-28 19:50 +0000
            Re: ->= BartC <bc@freeuk.com> - 2015-11-28 19:14 +0000
              Re: ->= supercat@casperkitty.com - 2015-11-28 11:48 -0800
                Re: ->= glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-29 22:33 +0000
              Re: ->= glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-28 20:18 +0000
                Re: ->= Stephen Sprunk <stephen@sprunk.org> - 2015-11-28 18:15 -0600
                  Re: ->= glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-29 22:44 +0000
                    Re: ->= Stephen Sprunk <stephen@sprunk.org> - 2015-11-29 18:25 -0600
                    Re: ->= raltbos@xs4all.nl (Richard Bos) - 2015-11-30 10:21 +0000
              Re: ->= Keith Thompson <kst-u@mib.org> - 2015-11-28 13:10 -0800
                Re: ->= BartC <bc@freeuk.com> - 2015-11-28 22:12 +0000
                  Re: ->= raltbos@xs4all.nl (Richard Bos) - 2015-11-29 11:42 +0000
                    Re: ->= BartC <bc@freeuk.com> - 2015-11-29 14:24 +0000
                      Re: "->=" Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-29 10:33 -0500
                      Re: "->=" BartC <bc@freeuk.com> - 2015-11-29 17:49 +0000
                      Re: ->= supercat@casperkitty.com - 2015-11-29 11:50 -0800
                        Re: ->= BartC <bc@freeuk.com> - 2015-11-29 22:37 +0000
                  Re: ->= Keith Thompson <kst-u@mib.org> - 2015-11-30 00:23 -0800
                Re: ->= glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-29 23:00 +0000
                  Re: ->= Keith Thompson <kst-u@mib.org> - 2015-11-30 00:28 -0800
                  Re: ->= Rosario19 <Ros@invalid.invalid> - 2015-12-13 16:29 +0100
    Re: ->= Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-28 14:59 -0500

Page 3 of 3 — ← Prev page 1 2 [3]


#77411

FromBartC <bc@freeuk.com>
Date2015-11-29 22:37 +0000
Message-ID<n3fuj8$ib2$1@dont-email.me>
In reply to#77406
On 29/11/2015 19:50, supercat@casperkitty.com wrote:

> As I see it, the sensible pattern for relational and short-circuit operators
> would be "if (rhs satisfies condition) lhs=rhs;".  While I I'm not sure how
> such things should be done syntactically, I think it would be useful to have
> compound operators which perform:
>
>     if (a < b) a=b;
>     if (a > b) a=b;
>     if (!b) a=b; // Not evaluating expressions within a if b is not zeroish
>     if (b) a=b; // Not evaluating expressions within a if b is zeroish

Getting an easy, obvious syntax is the tricky bit. For the first two, 
how about:

     a max= b;   // a = max(a,b)
     a min= b;

although there's the small problem that min/max aren't operators in C.

I can't do the other two in a way that evaluates a and b at most once 
each without introducing new syntax.

> Note that no existing operators behave in those ways [IMHO, && and || should
> have yielded the last-evaluated value, rather than coercing to integer 1
> and integer 0;

I'm not sure how that works. So:

   12 && 16 => 16 ?
   12 && 0  => 12 or 0? 0 was evaluated last.
   0  && 16 => 0?

   12 || 16 => 12 ?
   12 || 0  => 12 ?
   0  || 16 => 16 ?

The last lot is like x = firsttrue(a,b,...) (and the first like x = 
lasttrue(a,b,...).)

Written as a ||= b, I think that would be equivalent to:

   if (!a) a=b;

But I can't express what a &&=b does in a way that sounds useful as that!


-- 
bartc

[toc] | [prev] | [next] | [standalone]


#77445

FromKeith Thompson <kst-u@mib.org>
Date2015-11-30 00:23 -0800
Message-ID<lna8pvyjxe.fsf@kst-u.example.com>
In reply to#77350
BartC <bc@freeuk.com> writes:
> On 28/11/2015 21:10, Keith Thompson wrote:
[...]
>> Presumably if you're evaluating `a &&= b` (or, in actual C, `a = a && b`),
>> you're already treating a as a "logically boolean" value.
>>
>>      int cond = isdigit(foo);
>>      cond &&= isdigit(bar);
>
> If isdigit() returns 0 or 1, then there's no need to use && here; & will do.

isdigit() *doesn't* necessarily return just 0 or 1.

[...]

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#77414

Fromglen herrmannsfeldt <gah@ugcs.caltech.edu>
Date2015-11-29 23:00 +0000
Message-ID<n3g025$gea$1@speranza.aioe.org>
In reply to#77348
Keith Thompson <kst-u@mib.org> wrote:

(snip)

> Then you wouldn't normally write `count &&= b`, just as you wouldn't
> write `sqrt('x')`.

Not sqrt('x') but PL/I allows for sqrt('1234.56e2');

PL/I can do:
   
DCL (W, X, Y, Z) CHARACTER(100);

X='1';
Y='   100';
Z='1';
DO W=X TO Y BY Z;
   PUT SKIP LIST(W, SQRT(W));
END;

a little harder in C:

char t[100], w[100], x[100], y[100], z[100];
strcpy(x,'1');
strcpy(y,'100');
strcpy(z,'1');
for(strcpy(w,x), strcmp(w,y)<=0; sprintf(w,"%d",atoi(w)+atoi(z))) {
   sprintf(t,"%e", sqrt(atod(w)));
   printf("%s %s\n", w, t);
   }


I didn't try compiling it.  The PL/I code I wrote in high school,
when C was barely just a baby.  Getting the comparison right is
a little tricky.

-- glen

[toc] | [prev] | [next] | [standalone]


#77446

FromKeith Thompson <kst-u@mib.org>
Date2015-11-30 00:28 -0800
Message-ID<ln610jyjq5.fsf@kst-u.example.com>
In reply to#77414
glen herrmannsfeldt <gah@ugcs.caltech.edu> writes:
> Keith Thompson <kst-u@mib.org> wrote:
> (snip)
>
>> Then you wouldn't normally write `count &&= b`, just as you wouldn't
>> write `sqrt('x')`.
>
> Not sqrt('x') but PL/I allows for sqrt('1234.56e2');

I'm guessing that '1234.56e2', and that in this context it's
implicitly converted to a floating-point value of 1234.56e2.
Which means that something like sqrt('1234.56e2') could make
sense, particularly if the argument is some user input rather than
a literal.  The point of my example sqrt('x') is precisely that it
almost certainly *doesn't* make sense, though it's legal.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#78541

FromRosario19 <Ros@invalid.invalid>
Date2015-12-13 16:29 +0100
Message-ID<sm3r6b9h49qorcge8d15sthfr7di8hchj8@4ax.com>
In reply to#77414
On Sun, 29 Nov 2015 23:00:22 +0000 (UTC), glen herrmannsfeldt wrote:
>a little harder in C:
>
>char t[100], w[100], x[100], y[100], z[100];
>strcpy(x,'1');
>strcpy(y,'100');
>strcpy(z,'1');
>for(strcpy(w,x), strcmp(w,y)<=0; sprintf(w,"%d",atoi(w)+atoi(z))) {
>   sprintf(t,"%e", sqrt(atod(w)));
>   printf("%s %s\n", w, t);
>   }
>
>
>I didn't try compiling it.  The PL/I code I wrote in high school,
>when C was barely just a baby.  Getting the comparison right is
>a little tricky.
>
>-- glen

it should be not ' but "

char t[100], w[100], x[100], y[100], z[100];
strcpy(x,"1");
strcpy(y,"100");
strcpy(z,"1");

[toc] | [prev] | [next] | [standalone]


#77344

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2015-11-28 14:59 -0500
Message-ID<n3d0uu$p9q$1@dont-email.me>
In reply to#77164
On 11/25/2015 9:53 AM, glen herrmannsfeldt wrote:
> In a recent post on linked list, there was the common notation:
>
>      p = p->next;
>
> Though I have written it many times, this time it occured to me
> that there could have been a C operator ->= such that:
>
>     p ->= next;
>
> That is, similar to the way we have i += 2; instead of i=i+2;

     There could also be a compound function-call-and-assign operator:

	fptr()=;
or
	fptr(args)=;

This would be useful with pointers to functions that return pointers of
the same type (cf. Question 1.22 at <http://www.c-faq.com/>).

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

[toc] | [prev] | [standalone]


Page 3 of 3 — ← Prev page 1 2 [3]

Back to top | Article view | comp.lang.c


csiph-web