Skip to content

Fruit Language

Kamil Adam edited this page Aug 22, 2023 · 3 revisions

Basic Syntax

Basic Syntax uses only two special chars \ and `

Abstraction Lambda

\param body

Application Lambda

`fun arg

Sugar Syntax

Sugar Syntax uses (){}[]"'+=. ;, ,, . and : are not syntax but functions.

Multi Application

(f x y z)

Desugared

```f x y z 

Local scope

{
  ;(a b) \val1
  ;(a b c) \val2
  val1 val2
}

Desugared

(
  ;(a b) \val1
  ;(a b c) \val2
  val1 val2
)
  1. ; is T combinator

NilList (or Stack)

List with nil in end. But maybe better name is Stack. Lists are lazy because in Pure Functional Fruit everything is lazy.

[, a , b , c ]

Desugared

(, a , b , c .)
  1. , is V combinator via pair/cons.
  2. . is nil.

Strings

Strings are lazy because string is NilList of chars.

"Hello"

Desucared:

[, 'H , 'e , 'l , 'l , 'o]

Char

It is only literal. In code it is the same like Natural.

'a

Numbers

  • Natural -> generated, for numbers we need defined . (nil) and : (succ), so:
    • 0 is .
    • 1 is : .
    • 2 is : (: .)
  • Integer -> pair sign natural, sign is bool, plus is false, minus is true, so:
    • +0 is , false .
    • -0 is , true .
    • +1 is , false (: .)
    • -1 is , true (: .)

Extra Syntax

Extra Syntax uses two chars # and @.

Comment

# this is comment

Combinators - assembler of lambda

Work in progress.

Because Fruit can by compiled to Combinators, we can write alternative implementation in Combinators

Compiled to Combinators

@K

IO

Input is String and Output is String. So all program is function which consume String and produce String

Libraries

For libraries we need one hack. Library (a separate file with functions) must end with the function _.

;(a b) \val1
;(a b c) \val2
_

We use also one special char ~

~ true  (\x \y x)
~ false (\x \y y)