Re: using same variable twice on same page [message #171376 is a reply to message #171340] |
Fri, 31 December 2010 01:59 |
The Natural Philosoph
Messages: 993 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
Peter H. Coffin wrote:
> On Thu, 30 Dec 2010 02:07:59 +0100, August Karlstrom wrote:
>> On 2010-12-29 11:42, Derek Turner wrote:
>>> On Tue, 28 Dec 2010 22:07:55 -0700, richard wrote:
>>>
>>>> <?php if ($year="1961")
>>>
>>> This simply sets $year to "1961" and will always return 'true'
>> ...which is more or less a flaw in the language design copied from C.
>
> ... and a correction of a flaw in any language design copied from
> Fortran. We can do this all day.
>
Oh yes. Fortran. I'd forgotten Fortran...those godawful number to string
printing statements..
|
|
|
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171377 is a reply to message #171344] |
Fri, 31 December 2010 02:07 |
The Natural Philosoph
Messages: 993 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
August Karlstrom wrote:
> On 2010-12-30 05:47, Jerry Stuckle wrote:
>> On 12/29/2010 8:07 PM, August Karlstrom wrote:
>>> On 2010-12-29 11:42, Derek Turner wrote:
>>>> On Tue, 28 Dec 2010 22:07:55 -0700, richard wrote:
>>>>
>>>> > <?php if ($year="1961")
>>>>
>>>> This simply sets $year to "1961" and will always return 'true'
>>>
>>> ...which is more or less a flaw in the language design copied from C.
>>
>> Not at all. == is a completely different operator than =. Just like ++
>> is not the same as +.
>
> The equal sign `=' has been used in mathematics since medieval times to
> denote equality. To use `==' for equality and `=' for something else
> (assignment) is not sensible.
>
well in assembler its
MOV b,a
or
CMP a,b
And it used to be
LET a=b
and
if a=b
But the drive towards compactness on like editors meant that it got
turned into a=b;
You might argue endlessly about the need for two different operators and
whether 'a equals b' is more natural to regard as an assignment or a
comparison.
I argue that complex conditionals and assignments depending on them get
pretty screwed if you let the compiler decide what you really mean.
take
(a=b==c)
Its very clear which is an assignment and which is a comparison, though
the order or precedence is less so..
I don't know how you would write than in 'context dependent equals'
language, at all.
>
> /August
>
|
|
|
Re: using same variable twice on same page [message #171382 is a reply to message #171375] |
Fri, 31 December 2010 09:57 |
Tim Streater
Messages: 328 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
In article <ifjdb0$r2s$2(at)news(dot)albasani(dot)net>,
The Natural Philosopher <tnp(at)invalid(dot)invalid> wrote:
> Tim Streater wrote:
>> In article <ifhj8t$1hd$2(at)news(dot)albasani(dot)net>,
>> The Natural Philosopher <tnp(at)invalid(dot)invalid> wrote:
>>
>>> August Karlstrom wrote:
>>>> On 2010-12-29 11:42, Derek Turner wrote:
>>>> > On Tue, 28 Dec 2010 22:07:55 -0700, richard wrote:
>>>> >
>>>> >> <?php if ($year="1961")
>>>> >
>>>> > This simply sets $year to "1961" and will always return 'true'
>>>> > ...which is more or less a flaw in the language design copied from C.
>>>
>>> Which is more or less a feature of clarity,....not a flaw.
>>>
>>> BASIC is the flawed language, allowing '=' to mean SET TO and EQUALS
>>> according to ambiguous context
>>>
>>> Sadly PHP copied BASICS lack of explicit typing as well.
>>
>> I don't want explicit typing. Let the language work for you.
>>
> I guess I am not lazy enough and prefer the language to do exactly what
> I tell it.
Well - there it is. So far it has :-)
--
Tim
"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
|
|
|
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171383 is a reply to message #171377] |
Fri, 31 December 2010 10:14 |
August Karlstrom
Messages: 16 Registered: October 2010
Karma: 0
|
Junior Member |
|
|
On 2010-12-31 03:07, The Natural Philosopher wrote:
[...]
> take
>
> (a=b==c)
>
> Its very clear which is an assignment and which is a comparison, though
> the order or precedence is less so..
>
> I don't know how you would write than in 'context dependent equals'
> language, at all.
I'm not advocating "context dependant equals"; I think that a different
symbol should be used for assignment, e.g. `:='.
/August
--
The competent programmer is fully aware of the limited size of his own
skull. He therefore approaches his task with full humility, and avoids
clever tricks like the plague. --Edsger Dijkstra
|
|
|
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171384 is a reply to message #171383] |
Fri, 31 December 2010 10:47 |
The Natural Philosoph
Messages: 993 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
August Karlstrom wrote:
> On 2010-12-31 03:07, The Natural Philosopher wrote:
> [...]
>> take
>>
>> (a=b==c)
>>
>> Its very clear which is an assignment and which is a comparison, though
>> the order or precedence is less so..
>>
>> I don't know how you would write than in 'context dependent equals'
>> language, at all.
>
> I'm not advocating "context dependant equals"; I think that a different
> symbol should be used for assignment, e.g. `:='.
>
>
I thought a lot of things when I first tried to program a computer.
I probably thought a lot of things when as a 12 month old baby I tried
to learn English.
But I managed to struggle on with both, and I can now understand
important things like the difference between 'lose' and 'loser', and
'loose', and 'looser'. And '=' and '==' and '!='
Not to mention a number system mased on 10, a currency based on 240 and
a weights and measures system based on how many hoses' hooves you could
fry up for breakfast without being sick, or something equally arbitrary.
The important thing about standards and conventions is that they exist.
Less so what they are.
> /August
>
|
|
|
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171390 is a reply to message #171383] |
Fri, 31 December 2010 16:12 |
Jim Higgins
Messages: 20 Registered: November 2010
Karma: 0
|
Junior Member |
|
|
On Fri, 31 Dec 2010 11:14:37 +0100, August Karlstrom
<fusionfile(at)gmail(dot)com> wrote:
> On 2010-12-31 03:07, The Natural Philosopher wrote:
> [...]
>> take
>>
>> (a=b==c)
>>
>> Its very clear which is an assignment and which is a comparison, though
>> the order or precedence is less so..
>>
>> I don't know how you would write than in 'context dependent equals'
>> language, at all.
>
> I'm not advocating "context dependant equals"; I think that a different
> symbol should be used for assignment, e.g. `:='.
You are welcome to think that, but you won't have much success
programming in PHP unless you use "=" for assignment.
|
|
|
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171391 is a reply to message #171390] |
Fri, 31 December 2010 16:33 |
me
Messages: 192 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 12/31/2010 11:12 AM, Jim Higgins wrote:
> On Fri, 31 Dec 2010 11:14:37 +0100, August Karlstrom
> <fusionfile(at)gmail(dot)com> wrote:
>
>> On 2010-12-31 03:07, The Natural Philosopher wrote:
>> [...]
>>> take
>>>
>>> (a=b==c)
>>>
>>> Its very clear which is an assignment and which is a comparison, though
>>> the order or precedence is less so..
>>>
>>> I don't know how you would write than in 'context dependent equals'
>>> language, at all.
>>
>> I'm not advocating "context dependant equals"; I think that a different
>> symbol should be used for assignment, e.g. `:='.
>
>
> You are welcome to think that, but you won't have much success
> programming in PHP unless you use "=" for assignment.
>
By analogy, write down the grade you are in ($grade=12). If you are in
12th grade (if $grade==12) then you may graduate at the end of the year
(all other things equal).
Bill B
|
|
|
Re: using same variable twice on same page [message #171461 is a reply to message #171191] |
Wed, 05 January 2011 01:00 |
spambait
Messages: 35 Registered: September 2010
Karma: 0
|
Member |
|
|
In article <yzhlacpa809x(dot)dlg(at)evanplatt(dot)sux>, richard <member(at)newsguy(dot)com> wrote:
> Everything I have looked at so far talks of how to use one variable ONCE!
> Nothing I've seen even comes to close as to how to utilize the same
> variable in a different location on the same page.
>
> for instance:
> initial value of $year="1960"
> <div> <?php echo $year;?></div>
> <div> blah blah blah </div>
> <div> yada yada yada </div>
> Assume here we change $year to be "1961"
Mind showing us how you did that?
> <div> <?php if ($year="1961") echo $year; ?></div>
>
> From what I've tried, no change is made.
I'd imagine not.
> Even if I use a second instance of $_GET().
>
> What is the best way of doing what I want to happen?
Start by looking at the PHP manual to determine the correct operator to use
for making equality comparisons.
|
|
|
Re: using same variable twice on same page [message #171462 is a reply to message #171211] |
Wed, 05 January 2011 01:10 |
spambait
Messages: 35 Registered: September 2010
Karma: 0
|
Member |
|
|
In article <javru7-7ht(dot)ln1(at)qqqqq(dot)xs4all(dot)nl>, Luuk <Luuk(at)invalid(dot)lan> wrote:
> On 29-12-10 15:15, Captain Paralytic wrote:
[...]
>>
>> Now either [Richard] has not had the intelligence to have searched for php
>> tutorials, or he has done them but has not had the intelligence to
>> understand anything he has done.
>
> Since when do you care about the intelligence of anyone else?
> He definitely wants to learn, otherwise he would not post a question here.
I don't agree that Richard wants to learn -- his posts don't indicate any
desire to increase his understanding, only a desire to be given the solution
to his immediate problem. Confucius supposedly said, "Give a man a fish, and
you feed him for a day. Teach him how to fish, and you feed him for a
lifetime." Richard wants only to be given fish, and actively resists being
guided to resources that will help him learn to fish.
|
|
|
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171621 is a reply to message #171353] |
Wed, 12 January 2011 15:50 |
sheldonlg
Messages: 166 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 12/30/2010 1:36 PM, Jim Higgins wrote:
> On Thu, 30 Dec 2010 15:35:10 +0100, August Karlstrom
> <fusionfile(at)gmail(dot)com> wrote:
>
>> On 2010-12-30 05:47, Jerry Stuckle wrote:
>>> On 12/29/2010 8:07 PM, August Karlstrom wrote:
>>>> On 2010-12-29 11:42, Derek Turner wrote:
>>>> > On Tue, 28 Dec 2010 22:07:55 -0700, richard wrote:
>>>> >
>>>> >> <?php if ($year="1961")
>>>> >
>>>> > This simply sets $year to "1961" and will always return 'true'
>>>>
>>>> ...which is more or less a flaw in the language design copied from C.
>>>
>>> Not at all. == is a completely different operator than =. Just like ++
>>> is not the same as +.
>>
>> The equal sign `=' has been used in mathematics since medieval times to
>> denote equality. To use `==' for equality and `=' for something else
>> (assignment) is not sensible.
>
>
> All fine and dandy if you're programming in BASIC, but when
> programming in PHP you'll either do it as PHP requires or you'll not
> get the result you expect. Sensible or not that's the way it is. Your
> choice.
Now hand him what "===" means :-)
I just stepped in from and haven't read the history of this thread.
However, just from this little bit I can see that he doesn't know
programming at all. I'll bet he even thinks that
$a = 11;
means that the variable $a is equal to 11 and that this is an equation.
(Hint August: It isn't an equation. It is an expression that you are
taking the value 11 and setting the value of 11 into to the memory
location denoted by the variable $a).
Programming != mathematics.
Anyway, perhaps August should pick up a book on C, C++, Java and see
what they use for tests of equality before he criticizes PHP.
--
Shelly
|
|
|
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171622 is a reply to message #171360] |
Wed, 12 January 2011 15:53 |
sheldonlg
Messages: 166 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 12/30/2010 2:45 PM, August Karlstrom wrote:
> On 2010-12-30 20:21, richard wrote:
>> On Thu, 30 Dec 2010 15:35:10 +0100, August Karlstrom wrote:
>>> The equal sign `=' has been used in mathematics since medieval times to
>>> denote equality. To use `==' for equality and `=' for something else
>>> (assignment) is not sensible.
>>
>> Not really. As in various programming languages dictate, usage and
>> display
>> can be quite different.
>>
>> In BASIC and simpler low level languages, we say<>, meaning "not equal"
>> while in the higher level languages we say, !=.
>
> The symbols `/=' and `#' are also used in some high-level languages. It
> is unfortunate that the not-equal-to sign is neither on a standard
> keyboard nor in the 7-bit ASCII table. As a general guideline, however,
> I don't think language designers should redefine the meaning of well
> known symbols from mathematics. Or why not let `+' be the
> increment-by-one operator and `++' denote addition? Why not? After all,
> as Jerry Stuckle mentioned, programming is not mathematics.
>
>
> /August
>
August, I am a very big fan of the New England Patriots football team.
The coach, Bill Belichik has a favorite expression -- "It is what it is".
IOW, live with it.
(This is a stupid thread).
--
Shelly
|
|
|
Re: using same variable twice on same page [message #171623 is a reply to message #171375] |
Wed, 12 January 2011 15:54 |
sheldonlg
Messages: 166 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 12/30/2010 8:57 PM, The Natural Philosopher wrote:
> Tim Streater wrote:
>> In article <ifhj8t$1hd$2(at)news(dot)albasani(dot)net>,
>> The Natural Philosopher <tnp(at)invalid(dot)invalid> wrote:
>>
>>> August Karlstrom wrote:
>>>> On 2010-12-29 11:42, Derek Turner wrote:
>>>> > On Tue, 28 Dec 2010 22:07:55 -0700, richard wrote:
>>>> >
>>>> >> <?php if ($year="1961")
>>>> >
>>>> > This simply sets $year to "1961" and will always return 'true'
>>>> > ...which is more or less a flaw in the language design copied
>>> from C.
>>>
>>> Which is more or less a feature of clarity,....not a flaw.
>>>
>>> BASIC is the flawed language, allowing '=' to mean SET TO and EQUALS
>>> according to ambiguous context
>>>
>>> Sadly PHP copied BASICS lack of explicit typing as well.
>>
>> I don't want explicit typing. Let the language work for you.
>>
> I guess I am not lazy enough and prefer the language to do exactly what
> I tell it.
I, too, would prefer strict typing as well. That would eliminate many
errors where you think you have numbers but really have strings.
However, on the whole, PHP is great.
--
Shelly
|
|
|
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171624 is a reply to message #171383] |
Wed, 12 January 2011 15:57 |
sheldonlg
Messages: 166 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 12/31/2010 5:14 AM, August Karlstrom wrote:
> On 2010-12-31 03:07, The Natural Philosopher wrote:
> [...]
>> take
>>
>> (a=b==c)
>>
>> Its very clear which is an assignment and which is a comparison, though
>> the order or precedence is less so..
>>
>> I don't know how you would write than in 'context dependent equals'
>> language, at all.
>
> I'm not advocating "context dependant equals"; I think that a different
> symbol should be used for assignment, e.g. `:='.
>
>
> /August
>
I can't recall. Which language does that?
--
Shelly
|
|
|
|
|
|
|
Re: OT: Assignment operator [message #171634 is a reply to message #171626] |
Wed, 12 January 2011 23:14 |
sheldonlg
Messages: 166 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 1/12/2011 11:05 AM, Sherm Pendley wrote:
> sheldonlg<sheldonlg(at)thevillages(dot)net> writes:
>
>> On 12/31/2010 5:14 AM, August Karlstrom wrote:
>>> On 2010-12-31 03:07, The Natural Philosopher wrote:
>>> [...]
>>>
>>> I'm not advocating "context dependant equals"; I think that a different
>>> symbol should be used for assignment, e.g. `:='.
>>
>> I can't recall. Which language does that?
>
> Pascal, for one. I assume its descendants - Modula& Oberon - do so
> as well.
>
> sherm--
>
Thanks! I thought that was it, but it has been over twenty five years
since I touched Pascal (and even then it was very little), so I didn't
want to make a declarative statement only to have the response "No, it
isn't, you dummy" :-).
--
Shelly
|
|
|