Salt

From Esolang
(Redirected from Ojc)
Jump to navigation Jump to search

Salt (standing for S(m)al(l)t(alk)) is an object-oriented language invented by User:A designed to be very concise. It was influenced by Smalltalk.

Language overview

Salt is an object-oriented language that only contains objects and applications. Here is a 'Hello, world' program:

'Hello, world'

As you see here, it is a string object. You can also do applications to the object like this:

1.2+

Here, this takes the integer object(1) and, with another integer object(2), applies addition(+). The whole language falls in place. (It uses postfix because it is easy to implement.)

You may not use spaces in Salt, as a space indicates a one-line comment(and the source code may ONLY contain 1 line of code).

The languag has operator precedence, but I would be glad if anyone converts this notation to an infix version.

Of course, you can insert nops between them:

1.2.+

Nops in Salt concatenate the previous Object object (namely the Object object, which is the father object of all objects in Salt) with the succeeding Object object, therefore evaluating to an expression without itself.

The following contents are postfix and will be modified in the future. Please don't rely on these examples.

For a more complex example, here is a program that checks whether a number is divisible by 2.

i2%['true']Ṭ['false']ḟ

Quotes and brackets are auto-completed. Here,

i                      is an input object; when called by itself, it returns the input's value converted to its appropriate type.
 2%                    modulos the value by 2 in postfix.
   ['true']            Returns 'true'
           Ṭ           Postfix application of the integer object to check if it is a C-defined true; i.e. nonzero.
            ['false']  Returns 'false'
                     ḟ application of the integer object to check if it is a C-defined false; i.e. zero.

A same-byte answer that demonstrated dependent types:

iẹ«['true']Ṭ['false']ḟ

Explained:

i                      Is the input
 ẹ                     the "even number" class (A subclass of integer)
  «                    a subclass of?
   ['true']            Return true
           Ṭ           If that is true
            ['false']  Return false
                     ḟ If that is false

Arrays

Unlike Smalltalk, you do not have to waste bytecount to specify the length of the array.

x = Ɲ

Changing elements of the array is not done using the = operator; this operator is used only to bind names to objects. In fact, you never modify data structures; instead, you send a message to the object, and it will modify itself.

x@4

Index the array

x@4←99

Initialize this index as 99.

Note that the object stored in an array is just like any other object, so we can do things like:

(x @ 1) + 1

Sets

x = Ṇ

Create a set

x¦5.x¦22.x¦'add'

Toss things into the set(5,22,'add') The period is optional on the end of the line.

Golfed:

x¦5;¦22;¦'add'

The ; operator refers to the previous object.

You want to type ʂ when you are only interested in returning the object itself. E.g.

x + 5; + 5; + 5; + 5; ʂ

Just returns the value of the object x.

You can simply do this too:

External links