KDL language

(Help file for Alpha 1.1)

All rights reserved, Kallel A.Y KDL language © 2009-2012

 

Ways of using KDL

There are two ways to access KDL:

·         Interactive Shell

·         Through command line

 

1.       Interactive Shell

The interactive shell allows you to directly interact with KDL language and so directly programming inside ‘terminal’/’console’/’shell’

 

 

 

 

 

 

2.       Through Command line

Allows you to run a script (batch) file:

File.bat’s content

KDL_reformed.exe scriptfile.txt

 

 

 

 

 

 

PLEASE DON’T COPY PASTE ANY CODE, RATHER HANDLY TYPE IT

You can use:

Set alwaysontop
to keep console always on top

 

First Shell execution (program):

Usually, since KDL is after all a language, probably “Hello world” should be the first program

Ø  Write Hello world

But I guess, that won’t be enough.

Now about assigning we use

Ø  Variable <- Content

For example,

Ø  Zone de Texte: HelloZone de Texte: Hihello <- hi

Now, we’ve got a variable called ‘Hello’ and it contains hi

Ø  Write Hello world

Will now outputs:

Hi world   

But we want to show both of ‘Hi’ and ‘Hello’!

We use then dishes:

Ø  Write Hello and “hello” world

Result:

Hello and hi world    

So resuming all:

 

 

 

First program:

Last Chapter, we saw how to create our first execution, this time we’ll see how to create a simple program

Needed: Open Notepad, Notepad2 or Notepad++ or any equivalent program you find good for text editing (I use Notepad and Notepad++ by the way, gedit for linux)

The object of this is to write “My name is <name> <familyname>”

For that, we’ll have to study variables

If it’s too hard to understand, don’t worry, just skip!

Variables:

 

We saw that KDL is able to understand

Ø  Zone de Texte: HelloZone de Texte: Hihello <- hi

for creating:

 

But what we don’t know is, what is hello anyway? It contains Hi, no? yes it does but that’s not the question

Now, let’s do this syntax

Ø  hello <- hi

Ø  hello??

Result:

expr 

By going back to ‘References’, variable types, you’ll see

Obj
Expr

Object
Expression

All of above

Contains anything and everything including expression/1-line function

So, Hello is an ‘expression’, that would mean it can contain anything (integer, float, string etc)

For safety and memory management, it’s more recommended to use String instead of expression

But it’s not too late to do that

We have to define ‘Hello’ as a string

Ø  define hello as string

then IF we write

Ø  hello?

Ø  Hello??

Result:

Hi
str

That would mean, by redefining hello as a string, KDL won’t remove it, but will keep it and convert it to a string

So converting from expression to string is permitted: It’s called Legal

So, now, we’ll start defining 2 new strings

Ø  define name as string

Ø  define familyname as string

then we write:

Ø  write “What’s your name?”

Ø  read(name)

Ø  write “what’s your family name?”

Ø  read(familyname)

Ø  write “hello” name familyname

Now the question is why not use ‘write what’s your name?’ without dishes, there are 2 problems:

1.       name variable is already assigned, it will output “what’s your” instead of “what’s your name”

2.       the question mark if once left at the end, it will evaluate the expression and give result, see References Assign, 1-line Functions and Processing

So for that, it’s better to get used to dishes to avoid problems

Now about the dishes, anything inside them WILL NOT be replaced, thus dishes are very useful

 

Now, if we test in KDL in interactive shell, we’ll see

But if we save our final text:

define name as string
define familyname as string
write “What’s your name?”
read(name)
write “what’s your family name?”
read(familyname)
write “hello” name familyname

as kdlscript.txt near of ‘KDL_reformed.exe’

 

Then we create a new text file containing

KDL_reformed.exe kdlscript.txt

And we save it as run1.bat

 

Then we go to

And double click on it

The result will be:

 

The difference between Interactive Shell and Program (script) is:
Interactive shell is for personal use, it’s verbose

Script (or program) is for personal and public use, it can be uploaded and run as a normal program

 

Example:Solving a Math/Physics problem

We’ve got this function: f(x) = A sin(ωt+ )

Let A be 2

ω =  

φ =

(1)    for x = 0, f(x) = 5, A?

(2)    It requires 5 seconds to do a full period, Calculate ω

(3)    Calculate f(1), f(2), f(10), f(16)

 

 

Solution:
Note : Since KDL doesn’t differenciate between t and T, we’ll rename T to T1

Ø  f<-A*sin(Omega*t+phi) 

Ø  Omega <- 2 * Pi / T1

Ø  Phi <- pi / 2

(1)

** f(0) = A*sin( = A * 1 = 5 => A = 5

 

Ø  A<- 5

(2)

** 5 seconds for a period means T = 5

 

Ø  T1<- 5

Ø  Omega ?

(3)

Ø  t<-1

Ø  f ?

Ø  t<-2

Ø  f ?

Ø  t<-10

Ø  f ?

Ø  t<-16

Ø  f ?

 

Example: English homework:

(1)    Define awkward

(2)    Spell awkward

(3)    Do a research about clocks

(4)    When was USB cable created?

Solution:

Ø  Dict awkward

ð  causing inconvenience

Ø  speak awkward

ð  Computer spells it:

Ø  Wiki clock

Ø  Wiki USB

ð  1994

KDL Syntax problems  difference:  (no need to read this if you’re not a programmer)

Technically, KDL uses a simplified syntax for example, in normal languages such as VB, C++, you’ll have to write:

Ø  Std::Cout<<”hello world”;

Ø   Msgbox(“Hello world”)

To identify that it’s about a string

KDL doesn’t work like that (which may cause problems, very severe problems for advanced programmers)

Ø  Write Hello world

As soon as I realized that, I included a cooperative syntax called ‘pseudo-algorithmic’

Ø  Write “Hello world”

Making it VB6-alike language

 

The general syntax of KDL looks like a decent language from Old KDL, VB6, VB.NET, Pascal, Maple and sagemath.
KDL is targeted for students, high school students and younger as well as normal computer users