Close

Typing

A project log for BCFJ

Because I want to create a good-for-all language borrowing qualities from Bash, BASIC, C, Forth and JavaScript

yann-guidon-ygdesYann Guidon / YGDES 04/02/2018 at 03:2615 Comments

What's best ? Pascal's strong typing or JS' weak typing ?

Both have excellent arguments but also significant drawbacks.

It's hard to reconcile both.

Since BCFJ starts as an interpreted language, typing can be weak and in fact, the first type is "a number" (think "int" in C).

Later, when objects ("blobs") are introduced (à la JS) a stronger typing mechanism can be introduced. The trick is to have/check the "type" attribute, which points to a collection of handlers that then resolve the types, convert or compute values...

So BCFJ does not enforce a typing mechanism or precise resolution behaviours from the beginning (this removes a LOT of red tape from the language). Later, conventions can be added to prevent inconsistencies or adopt the preferred behaviours.

So BCFJ starts "naked", like in FORTH, with an "integer" type, which is then completed... See the next logs.


Oh my...

Discussions

Morning.Star wrote 04/02/2018 at 20:31 point

You can please some of the people all of the time, or all of the people some of the time.

It appears to be universal :-D

  Are you sure? yes | no

Yann Guidon / YGDES wrote 04/02/2018 at 23:10 point

I know. This is why I stick to the goal : to develop a software framework to help bootstrap the ecosystem of my CPUs. That's why a non-perfect but flexible and functioning language is required, starting with a small scripted kernel (that doubles as a command-line interface) that evolves enough to write an assembler or a compiler (for itself or other languages). So BCFJ is a mean, not an end :-)

  Are you sure? yes | no

Morning.Star wrote 04/02/2018 at 05:48 point

I thought you'd like NaN lol. I didnt encounter it until I began throwing geometry around and made some funny values. ;-p

  Are you sure? yes | no

Yann Guidon / YGDES wrote 04/02/2018 at 05:57 point

One thing at a time, please ;-D

  Are you sure? yes | no

Morning.Star wrote 04/02/2018 at 05:23 point

How about Python's Dont Care attitude, and treat all things as equal unless they arent?

I like how Python converts inline so you dont have to declare types, but has a very formal way of going about the conversion.

I also like NaN, which resolves to zero with a warning. Please :-D

  Are you sure? yes | no

Yann Guidon / YGDES wrote 04/02/2018 at 05:37 point

The problem is that conventions, you know... everyone has their own.

And I care about coherence. I know it can quickly stab you in the back so I'm careful...

So by default, don't play with things that are not of the same type :-)

And NaN is another can of worms... Too many JS memories :-P

  Are you sure? yes | no

Yann Guidon / YGDES wrote 04/02/2018 at 05:40 point

Funny thing : JS provides the "==" and "===" comparison operators. The "===" checks if both operands have the same type and this is the behaviour that I prefer...

  Are you sure? yes | no

Morning.Star wrote 04/02/2018 at 05:54 point

Just so long as you make it complain about

if a = 0

and

a == 0

because Python does and C doesnt always. Its my favourite trick forgetting an equals, and the only thing I loved about BASIC which I learned first. ;-)

  Are you sure? yes | no

Yann Guidon / YGDES wrote 04/02/2018 at 06:00 point

Oh, comparison/assignation is yet another subject :-D

In ADA/VHDL there are the := and <= assignation operators (one is immediate and the other is delayed).

Then if == is comparison, we can finally get rid of the ambiguous "=" operator....

  Are you sure? yes | no

Yann Guidon / YGDES wrote 04/02/2018 at 06:53 point

And since "<=" can be confused with "less than or equal", there only remains "==" for strict equality and ":=" for assignation. "=" will throw an error.

  Are you sure? yes | no

Ted Yapo wrote 04/02/2018 at 14:56 point

"=" can throw an error until you add a computer algebra system to the pre-processor

  Are you sure? yes | no

Yann Guidon / YGDES wrote 04/02/2018 at 15:12 point

Ted: yep, something like that.

My strategy is to have a configurable parser, a bit like lex & yacc as standard modules, so parsing/analysis can be tweaked at will and the baseline language has a "default configuration".

  Are you sure? yes | no

deʃhipu wrote 04/02/2018 at 15:44 point

Actually the default equality function for objects in Python (used when you don't define your own) is to compare the object's id, so an object is only equal to itself, and not equal to anything else.

  Are you sure? yes | no

Morning.Star wrote 04/02/2018 at 20:20 point

Yeah that makes sense, otherwise you'd be able to make the statement

a==0 , resulting in 'a' containing True if 'a' already contained 0, and False if not.

Which results in another bind I have with languages, some use -1 for True and some use 1, and some use a bool type. Python does avoid that neatly by using types for everything and figuring out if it has a numeric value when it needs it.

  Are you sure? yes | no

deʃhipu wrote 04/02/2018 at 22:40 point

Python's bool type is a subclass of the int type, and True is equal to 1:

>>> issubclass(bool, int)
True
>>> isinstance(True, int)
True
>>> 1 == True
True
>>> 1 is True
False

Same for False and 0. You can actually do this:

>>> 2 + True
3

  Are you sure? yes | no