meaning of # in print #3 ...

New to FreeBASIC? Post your questions here.
Post Reply
softfoot
Posts: 54
Joined: Aug 31, 2020 3:45

meaning of # in print #3 ...

Post by softfoot »

I notice that the # is optional so you can use #3 or 3
Or you can use a variable like #f or f
So, what is the meaning of the # ??
Just curious ...
Dave
shadow008
Posts: 117
Joined: Nov 26, 2013 2:43

Re: meaning of # in print #3 ...

Post by shadow008 »

Interesting question. I couldn't find anything on the wiki about it, so I can only assume this is a holdover from qbasic compatibility.

https://www.qbasic.net/en/reference/qb1 ... /PRINT.htm
PaulSquires
Posts: 1007
Joined: Jul 14, 2005 23:41

Re: meaning of # in print #3 ...

Post by PaulSquires »

Interesting response from the elite AI minds deep inside ChatGPT:
Use of Symbols in Early Programming Languages

In the early days of computing, symbols like #, @, !, and others were often used as shorthand for common operations, memory locations, or registers because they were easy to recognize, type, and had no prior meanings in early programming contexts. At that time, memory and processing resources were extremely limited, so it was common to use concise notation.

Why # in BASIC for File Numbers?
Concise Identification: The # symbol was likely chosen as a simple and clear way to differentiate file or device numbers from other numeric values. It indicates to the interpreter that the number following it refers to a specific file or I/O device, rather than a value to be calculated or manipulated.

Limited Symbol Set: In the 1960s and 1970s, many early programming languages were designed to work with limited character sets, and the # was a convenient symbol that wasn’t already widely used for other purposes in BASIC.

Consistency Across Devices: The concept of using # for file numbers allowed BASIC to have a unified syntax for handling different I/O devices (such as printers, disk drives, or terminals). By assigning each device a file number (e.g., #1 for a file, #2 for a printer), BASIC could easily direct output to the correct destination.


Similar Usage in Other Early Languages
The use of # to reference specific file or device numbers can be seen in other early programming systems as well. For example:

In FORTRAN, you would use a UNIT= statement to specify file or device numbers for I/O operations.
In DOS/Batch scripts, the % symbol was used to indicate parameters or variables, similarly using a symbol to denote something special or reserved.

The overall goal was to keep the language simple and intuitive, especially for users who were learning to program for the first time.
softfoot
Posts: 54
Joined: Aug 31, 2020 3:45

Re: meaning of # in print #3 ...

Post by softfoot »

Many thanks for that.
Makes sence
Dave
Post Reply