Recent

Author Topic: := NOT  (Read 2150 times)

Zath

  • Sr. Member
  • ****
  • Posts: 391
:= NOT
« on: March 02, 2020, 05:23:16 pm »
How long has the syntax below been valid in pascal and is there somewhere I can look to see how it works ?
I was always trying lots of IFs, THENs etc. in the past.


Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   Shape1.visible := not Shape1.visible;
  4. end;
  5.  

eljo

  • Sr. Member
  • ****
  • Posts: 468
Re: := NOT
« Reply #1 on: March 02, 2020, 05:27:33 pm »
first time I used it was on turbo pascal 3

egsuh

  • Hero Member
  • *****
  • Posts: 1602
Re: := NOT
« Reply #2 on: March 02, 2020, 05:29:08 pm »
Well it should be read as  := (not something), not (:= not) something.

wp

  • Hero Member
  • *****
  • Posts: 12805
Re: := NOT
« Reply #3 on: March 02, 2020, 05:33:44 pm »
How long has the syntax below been valid in pascal
Forever (?).

It is easy. You certainly agree that something like "Shape1.Visible := false" works. Now, when "Shape1.Visible" is true initially, calling "NOT Shape1.Visible" inverts this boolean variable. And you can assign this boolean variable to "Shape1.visible" as stated in the first part of this paragraph.

This somehow reminds me that, a long time ago, I never understood constructions like "Shape1.Visible := x=1" - what about the double '=' here? It is the same as "if x = 1 then Shape1.Visible := true else Shape1.Vlsible := false" - the first '=' is part of the assignment operator ':=', the second is the check-for-equality operator.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: := NOT
« Reply #4 on: March 02, 2020, 05:52:11 pm »
Hi!

The syntax is much older than Pascal.

Look for Boolean Algebra and George Boole (1815-1864).

Winni

« Last Edit: March 02, 2020, 06:56:02 pm by winni »

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: := NOT
« Reply #5 on: March 03, 2020, 12:33:22 am »
Thanks for the replies people.
wp does go some way to explaining the working behind it.
I find it interesting how its a statement, a test and an assignment.


Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11181
  • Debugger - SynEdit - and more
    • wiki
Re: := NOT
« Reply #6 on: March 03, 2020, 12:42:07 am »
Thanks for the replies people.
wp does go some way to explaining the working behind it.
I find it interesting how its a statement, a test and an assignment.

It (depending on what "it" refers too) is not a test. It is (contains) an operation.

The "not" is an operator. It doesn't performs any test. It negates the value.

The "not" is the same, never mind if the term in which it occurs is on the lhs of an assignment, or in any other code.





del

  • Sr. Member
  • ****
  • Posts: 258
Re: := NOT
« Reply #7 on: March 03, 2020, 04:52:24 am »
Think of it as a boolean inversion.

guest58172

  • Guest
Re: := NOT
« Reply #8 on: March 03, 2020, 05:08:31 am »
How long has the syntax below been valid in pascal and is there somewhere I can look to see how it works ?
I was always trying lots of IFs, THENs etc. in the past.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   Shape1.visible := not Shape1.visible;
  4. end;
  5.  

well I'll give a try with a semi-technical explantation, I hope this will work.

if Shape1.Visible is a field:

  read Shape1.Visible into scratch%1
  assign scratch%1 to not scratch%1
  write scratch%1 into Shape1.Visible

if Shape1.Visible is a function (both setter, getter):

  call Shape1.Visible put result in scratch%1
  assign scratch%1 to not scratch%1
  call Shape1.Visible with scratch%1 as parameter

now, the problem is that Visible is certainly a property so depending on the "read" "write" what will happend can be a mix of the two.

otherwise... when it's not a function you have a dot operator... the dot LHS gives the address  and the dot RHS an offset (basically because with several dots its different). But in both cases (read/write) you have an adress to read or write given bu the expression.

when it's a function things get more complicated...

if Shape1 is variable and not a type then Shape1 still gives an adress but this address is called a "this" (or a "self").
Visible is a function of that takes an instance of Shape1 type as hidden parameter, so this function is called with the address of Shape1 as hidden param and also the other regular params. You see member functions are just an abstraction.But there are also static member functions or class functions... in this case Shape1 is just used to resolve and there's no hidden parameter.

dbannon

  • Hero Member
  • *****
  • Posts: 3353
    • tomboy-ng, a rewrite of the classic Tomboy
Re: := NOT
« Reply #9 on: March 03, 2020, 07:19:07 am »
first time I used it was on turbo pascal 3

Certainly reference to "the not operator and its operand" in my Turbo Pascal 2.0 Manual....

D
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

PascalDragon

  • Hero Member
  • *****
  • Posts: 5974
  • Compiler Developer
Re: := NOT
« Reply #10 on: March 03, 2020, 09:10:47 am »
Thanks for the replies people.
wp does go some way to explaining the working behind it.
I find it interesting how its a statement, a test and an assignment.

Let's break this down a bit.

A := not A

as a whole is a statement. This statements consists of an assignment operation with an expression on the left (A) and an expression on the right (not A).
The left expression is simply a load of A (compiler speak; one could also describe it as a store of the right expression into A).
The right expression consists of a not operation which has another expression (in this case A) as its operand. And again that A-expression is a load of A.

This is the same as if you'd have the following:

SomeInt := - SomeInt

Nothing special about that either.

Or:

SomeBool := SomeOtherBool or SomeThirdBool

MarkMLl

  • Hero Member
  • *****
  • Posts: 8398
Re: := NOT
« Reply #11 on: March 03, 2020, 10:29:48 am »
Thanks for the replies people.
wp does go some way to explaining the working behind it.
I find it interesting how its a statement, a test and an assignment.

I wonder if I could throw in a bit of detail to supplement what people have already said.

Code: [Select]
A := not A

There isn't really a single "it" in that. You shouldn't think about (the computer, or more specifically a compiler) processing that line as a single entity, instead what happens is something like this:

* The compiler starts looking for a statement.

* Possible statements include "if", "repeat" and so on, but in particular an assignment.

* An assignment starts off with "something to which a value can be assigned", in this case a variable "A". It is then followed by ":=".

* After the assignment, there is an expression.

* Possible expressions are function calls, numeric expressions and so on, but in particular logical evaluations.

* A possible logical evaluation is "not" followed by another logical evaluation.

* In the current example, the final/inner logical evaluation is "A", the fact that this is a variable which is also later being assigned too is irrelevant (all the stuff on the RHS of the assignment is completed before the assignment is actioned).

So "A" (from the RHS of the assignment) is pushed onto the stack or stored in a register. It is then operated on by "not". The value of the top stack element or some register is then assigned to "A".

For more detail, see e.g. https://www.cs.helsinki.fi/u/vihavain/k10/okk/minipascal/minipascalsyntax.html starting at "<assignment statement>" and then move down to "<expression>".

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: := NOT
« Reply #12 on: March 05, 2020, 11:57:25 am »
Interesting responses, thanks again all.

 

TinyPortal © 2005-2018