I am new to python. I have a few questions coming from an armature!

Ben Bacarisse ben.usenet at bsb.me.uk
Wed Aug 17 16:44:58 EDT 2016


MRAB <python at mrabarnett.plus.com> writes:

> On 2016-08-17 18:19, Jussi Piitulainen wrote:
>> MRAB writes:
>>
>>> On 2016-08-17 12:24, Jussi Piitulainen wrote:
>>>> BartC writes:
>>>>
>>>>> On 17/08/2016 07:39, Steven D'Aprano wrote:
>>>>>> Rather than ask why Python uses `trueval if cond else falseval`, you
>>>>>> should ask why C uses `cond ? trueval : falseval`. Is that documented
>>>>>> anywhere?
>>>>>
>>>>> I'm not fond of C's a ? b : c but the principle is sound. I generally
>>>>
>>>> [- -]
>>>>
>>>>> Anyway a?b:c was existing practice. At least the order of a,b,c could
>>>>> have been retained if not the exact syntax.
>>>>
>>>> The original was (c1 -> e1, c2 -> e2, ..., cn -> en) in John
>>>> McCarthy's 1960 paper on symbolic expressions, with an actual arrow
>>>> glyph in place of hyphen-greater-than.
>>>>
>>> [snip]
>>>
>>> BCPL, the ancestor of  C, had:
>>>
>>>     a -> b, c
>>
>> Nice. Add a redundant pair of parentheses and it's the same. (When used
>> as an expression, a final else-branch is mandatory-ish.)
>>
>> But C uses -> for something else, I think. And other languages use it
>> for lambda expressions (succesfully, I think, but then they don't have
>> it available for this purpose).
>>
> C uses "->" for dereferencing a pointer to the member of a struct.

Slightly better wording: it uses -> to access a struct member via a
pointer to the struct.

> If "p" points to a struct (record), then "*p" is that struct, and if
> that struct has a member (field) "m", then that member can be accessed
> by "(*p)->m" (the parens are necessary because of the operator
> precedence).

I think you meant (*p).m here because you go on to correct say that ->
offers a shorthand for this rather messy access:

> This can be abbreviated to "p->m".
>
> Pascal, on the other hand, dereferences with a postfixed "^", so that
> would be "p^.m".
>

-- 
Ben.



More information about the Python-list mailing list