I.T. Discussion Community!
-Collapse +Expand
Paradox
Search Paradox Group:

Advanced
-Collapse +Expand Paradox To/From
To/FromCODEGuides
-Collapse +Expand Paradox Store
PRESTWOODSTORE

Prestwood eMagazine

September Edition
Subscribe now! It's Free!
Enter your email:

   ► KBDesktop Data...Paradox & Ob...ObjectPAL Co...OPAL: Langua...   Print This     
 
Paradox OPAL: Language Basics:
ObjectPAL End of Statement (whitespace)
 
Posted 11 years ago on 12/14/2008 and updated 1/19/2009
Paradox Code Snippet:
 A flashcard from our Paradox Flashcards Library
 A code snippet from our Paradox Code Snippets Page

KB101694

Languages Focus: End of Statement

In coding languages, common End of statement specifiers include a semicolon and return (others exist too). Also of concern when studying a language is can you put two statements on a single code line and can you break a single statement into two or more code lines.

ObjectPAL End of Statement

ObjectPAL is a bit unique in that it doesn't use a semicolon nor a return to mark the end of a line, it uses whitespace which can be a return, space, or tab. This is a bit unusual but does allow for some nice formatting of code.

Syntax Example:
msgInfo("", "Hello1")
msgInfo("", "Hello2")
msgInfo("", "Hello3")

;The following single line of code also works.
msgInfo("", "Hello4") msgInfo("", "Hello5")

;Two or more works too:
msgInfo
("", "Hello6")

Comments

1 Comments.
Share a thought or comment...
First Comment
Comment 1 of 4

It's not so much that ObjectPAL uses whitespace instead of a semicolon or a return to mark the end of a statement, as that ObjectPAL doesn't mark the end of a statement at all.

It's up to the programmer to use white space and new lines to make his code clear.  The ObjectPAL parser doesn't care.

Advanced question: given that f(p) is defined as

proc f(const p longint) longint
   return p + p
endproc

what will this code do

   x = 7 + f(3)
   y = 7 - f(3)
   z = 7   f(3)

?

-A.I.Breveleri

Posted 8 years ago

Comment 2 of 4

Without typing it in, let me try a guess. First, is this a trick question? Did you mean to make the p parameter a const? If so, then what happens is an error.

As for the z example, z will equal 7 and because of the whitespace the "f(3)" is considered a new line of code that in this case does nothing.

Off to Paradox...ok, I was right. What do I get? Laughing

here's a working version:

proc f(const p longint) longint
   return p + p
endproc
method pushButton(var eventInfo Event)
 var
  x,y,z LongInt
  a LongInt
 endVar
 
 a = 3
 x = 7 + f(a)   
 msgInfo("", x)   ;display 13.
 y = 7 - f(a)
 
 msgInfo("", y)  ;display 1.
 
 z = 7   f(a)
 msgInfo("", z) ;display 7, f(3) does nothing.
endMethod
Posted 8 years ago

Comment 3 of 4

Correct as always, Mike.

(1) The "const" is an error.  The line should be

proc f(p longint) longint

This wasn't a trick, just a coding error.  Sorry.

(2) Right.  The result of "f(3)" is ignored.  If you encounter a line like this, not in the context of discussing statement-endings, especially after trying to code, say, "z = 7 + f(3)", you may become very confused for a long time.  Guess how I know this.

(3) You get to write another book!  A collection of bizarre and confusing errors in the most popular languages.  You could call it "Unsafe in Any Language".

-A.I.Breveleri.

Posted 8 years ago

Latest Comment
Comment 4 of 4

>>(2) Right. The result of "f(3)" is ignored.

Yeah! I got it right! The book idea is a good one. I like the title too. I have a few books I'm in the middle of and hope to publish later this year.

Posted 8 years ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1162A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile


Linked Certification Question(s)

The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

Intermediate

1 Intermediate Level Question

Question #1: True or False?

It is legal to put two code statements on a single line as in the following:

msgInfo("", "hello")  msgInfo("", " world")
Answer:
  • True
  • False

  •  KB Article #101694 Counter
    8992
    Since 12/14/2008

    Follow PrestwoodBoards on: 


    ©1995-2019 PrestwoodBoards  [Security & Privacy]
    Professional IT Services: Coding | Websites | Computer Tech