Giter Club home page Giter Club logo

pineapple's Introduction

Pineapple Language

Build status Result
Travis CI Build Status
Circle CI CircleCI
Code coverage codecov

Pineapple is a language that focus on maintainability.

Read more at Pineapple Documentation.

pineapple's People

Contributors

wongjiahau avatar hyliew322 avatar

Stargazers

Cat Stevens avatar Andrew Johnson avatar  avatar Cookie Engineer avatar Gavin Ray avatar Giorgio Garofalo avatar Mateo Contenla avatar Ben Morris avatar Ilya Sher avatar Gilbert avatar Alex Gravenor avatar Noah avatar  avatar Daniel Boulton avatar  avatar Niels Horn avatar S. B. Immington avatar Jeremy Grifski avatar ontofractal avatar Jörgen Brandt avatar  avatar Hugo Lundin Münch avatar Benjamin Philippe Applegate avatar Ruru Scarlet avatar

Watchers

Gilbert avatar James Cloos avatar Cat Stevens avatar  avatar  avatar

pineapple's Issues

Paper read

Simplifying PON

In the Object specification, do you really need the equal signs or prefixing every property with a .?

Example without:

// Pineapple 
myFruit
    name "Mango" 
    isTasty true
    sibling
        name "Durian"
        isTasty false
    amount 10 + 5

Example of Pineapple

def group :comparable

def this:T < that:T -> :boolean
    if :T is :comparable

def this:T == that:T -> :boolean
    if :T is :comparable

def this:T > that:T -> :boolean
    where :T is :comparable
    return this < that .Not.And(this == that .Not)
    
def this:T != that:T -> :boolean
    where :T is :comparable
    return this == that .Not

def this:T >= that:T -> :boolean
    where :T is :comparable
    return this > that .Or (this == that)

def this:T <= that:T -> :boolean
    where :T is :comparable
    return this < that .Or  (this == that)

def group :T:binaryTree
    where :T is :comparable

def thing :T:node 
    .value  :T
    .left   :T:binaryTree
    .right  :T:binaryTree
    
def :T:node is :T:binaryTree

def thing :emptyNode

def :emptyNode is :binaryTree

def this:T:X.Insert child:T -> :T:binaryTree
    if :X is :binaryTree 

def this:T:node.Insert child:T -> :T:binaryTree
    if this.value == child 
        return this
    if this.value < child 
        return this with 
            .left = this.left.Insert child
    if this.value > child
        return this with
            .right = this.right.Insert child
            
            
def this:emptyNode.Insert child:T -> :T:binaryTree
    return :T:node
        .value = child
        .left  = :emptyNode
        .right = :emptyNode

            
def this:T:list.ToTree -> :T:binaryTree
    return this.Foldr (_.Insert __) From :emptyNode 

def this:T:X.ToList -> :T:list
    if :X is :binaryTree

def this:emptyNode.ToList -> :T:list
    return []

def this:T:node.ToList -> :T:list
    return this.left.ToList 
        ++ [this.value] 
        ++ this.right.ToList

def this:T:X.Contains child:T -> :boolean
    if :X is :binaryTree
        
def this:emptyNode.Contains child:T -> :boolean
    return #false

def this:T:node.Contains child:T -> :boolean
    if this.value == child 
        return #true
    if this.value < child
        return this.left.Contains child
    if this.value > child
        return this.right.Contains child
    
def this:T:X.Minimum -> :T
    if :X is :binaryTree

def this:emptyNode.Minimum -> :T
    throw

def this:T:X.IsEmpty -> :boolean
    if :X is :binaryTree 

def this:emptyNode.IsEmpty -> #true
def this:T:node.IsEmpty -> #false


def this:T:node.Minimum -> :T
    if this.left.IsEmpty
        return this.value
    else 
        return this.left.Minimum

def this:T:X.Maximum -> :T
    if :X is :binaryTree

def this:emptyNode.Maximum -> :T
    throw

def this:T:node.Maximum -> :T
    if this.right.IsEmpty
        return this.value
    else
        return this.right.Maximum
        
def this:T:binaryTree.InOrder -> this.ToList

def this:T:X.PreOrder -> :T:list
    if :X is :binaryTree

def this:emptyNode.PreOrder -> :T:list
    return []

def this:T:node.PreOrder -> :T:list
    return [this.value] 
        ++ this.left.PreOrder
        ++ this.right.PreOrder

def this:T:X.PostOrder -> :T:list
    if :X is :binaryTree

def this:emptyNode.PostOrder -> :T:list
    return []

def this:T:node.PostOrder -> :T:list
    return this.left.PostOrder
        ++ this.right.PostOrder
        ++ [this.value]

Design by Contract

// compile time design by contract (not run time error!)

def this:table{:TKey to :TValue} .get that:TKey -> :TValue
	ensure this.hasKeyOf(that)
	// logic
	

// when using the function above 
let contact = :table{:string to :number}
	"wong" 123
	"lee"  456
	"john" 789

contact.get "wong" 
/* Compile error, you need to make sure the following is/are satisfied before you can call the `.get` function:
	
	ensure contact.hasKeyOf("wong") 

To satisfy the constraint above, you have two ways:

	1) Use an `if` statement to check the constraint
	
		For example,
		
			if contact.hasKeyOf("Wong")
				contact.get "wong" // No compile error 
			else 
				// do something
			
	2) Declare a similar `ensure` statement straight below the function signature
	
		For example,
		
			def this:number .divide that:number -> :number 
				ensure that.isNotZero
				return this .unsafeDivide that
			
			def this:number .anotherDivide that:number -> :number 
				ensure that.isNotZero
				return this.divide that // no compile error, because we already ensured that.isNotZero
	
	
	## Specification
	### The structure of ensure statement 
	
		EnsureStatement
			= `ensure` SingleBooleanFunctionCall
		
		SingleBooleanFunctionCall 
			= Variable FunctionName 
			| Variable FunctionName Variable
			| Variable FunctionName Variable SubFunctionName Variable
	
	Note that expression is not allowed inside SingleBooleanFunctionCall
	
	For example, the following is invalid:
	
		ensure this.length == that.length // invalid, function parameter cannot be expression
	
	While the following is valid:
	
		ensure this.hasEqualLengthWith(that)
	
*/

PON suggestion

Below is the format for array of object.

let myFruits =
	.1 = 	.name  = "Pineapple"
	 	.price = 13
	.2 =	.name  = "Durian"
		.price = 15
	.3 = 	.name  = "Rambutan"
		.price = 19
	

Expression Problem Solution

def Expression

def Constant
    :value Integer

def Constant is Expression

def Addition
    :left  Expression
    :right Expression

def Addition is Expression

def (this T).print -> String
    if T is Expression

def (this Constant).print -> String
    return this:value.toString

def (this Addition).print -> String
    return "$(this:left.print) + $(this:right.print)"

// if we want to add evaluate function on Expression
def (this T).evaluate -> Integer
    if T is Expression

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.