Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Language thread

Name: Anonymous 2018-12-23 1:36

Please rate my language. I was bored this night and so I ended up wasting my time writing this.
#!/usr/bin/env runhaskell

{-# LANGUAGE LambdaCase #-}

module Stack where

import Data.List
import Data.Char

type Stack = [Term]
type Ret = Either String Stack

data Term = I Int
| Q (Stack -> Ret)

eval :: String -> Ret
eval s = eval2 s [] "" 1

eval2space :: String -> Stack -> String -> Int -> Ret
eval2space (c:s) stack buf line = eval2space2 (' ':s) stack buf (case c of
'\n' -> line + 1
_ -> line) (c == '\n')
eval2space2 :: String -> Stack -> String -> Int -> Bool -> Ret
eval2space2 (' ':s) stack "" line _ = eval2 s stack "" line
eval2space2 (' ':s) stack buf line nl
| foldl' (\r -> \c -> isDigit c && r) True buf = eval2 s ((I (read buf :: Int)):stack) "" line
| True = primeval buf stack (case nl of
True -> line - 1
False -> line) >>= (\stack -> eval2 s stack "" line)

eval2 :: String -> Stack -> String -> Int -> Ret
eval2 ('[':s) stack "" line = inner s 0 "" line >>= (\(s, r, line2) -> eval2 s ((Q (\stack -> eval2 r stack "" line)):stack) "" line2)
where inner (']':s) 0 r line = return (s, r, line)
inner (c:s) i r line = inner s (case c of
']' -> i - 1
'[' -> i + 1
_ -> i) (r ++ [c]) (case c of
'\n' -> line + 1
_ -> line)
inner "" _ _ line = Left $ show line ++ ":EOF before ]"
eval2 ('[':s) stack _ line = Left $ show line ++ ":Expected space before ["

eval2 (c:s) stack buf line
| isSpace c = eval2space (c:s) stack buf line
| True = eval2 s stack (buf ++ [c]) line
eval2 "" stack "" line = return stack
eval2 "" stack buf line = eval2space " " stack buf line

primeval :: String -> Stack -> Int -> Ret
primeval s stack line = case lookup s prims of
Just (n, x)
| n <= length stack -> case x stack of
Left e -> Left $ show line ++ ":" ++ s ++ ":" ++ e
Right r -> return r
| True -> Left $ show line ++ ":Primitive " ++ s ++ " requres a stack that is at least " ++ show n ++ " big. Stack: " ++ show stack
Nothing -> Left $ show line ++ ":Primitive " ++ s ++ " not found. Stack: " ++ show stack

arithm name f = (name, (2, \case ((I a):(I b):t) -> return ((I $ f a b):t)
_ -> Left $ "Expected two numbers"))

prims = [("dup", (1, \(h:t) -> return (h:h:t))),
("pop", (1, \(_:t) -> return t)),
("eval", (1, \case ((Q f):t) -> f t
_ -> Left "Expected function")),
("if", (3, \case ((I 0):el:_:t) -> return (el:t)
((I _):_:t) -> return t
_ -> Left "First argument must be an integer")),
arithm "+" (+),
arithm "-" (-),
arithm "*" (*),
arithm "/" quot,
arithm "%" rem,
arithm "^" (^),
arithm "<" (\a -> fromEnum . (>) a),
arithm ">" (\a -> fromEnum . (<) a),
arithm "<=" (\a -> fromEnum . (>=) a),
arithm ">=" (\a -> fromEnum . (<=) a)]

main = getContents >>= (putStrLn . (\case Left s -> "Error: " ++ s
Right s -> show s) . eval)

instance Show Term where
show (I i) = show i
show _ = "function"


Examples:
[99] [11] 0 1 <= if eval
-> [99]


1 [1 +] eval dup
-> [2,2]


It is also turing complete. The following will not halt:
[dup eval] dup eval

Name: Language Rater 2018-12-23 4:23

>>1
I was bored this night

Looks good, like, "God was bored, so He created the universe."

But what is your native language? English-speakers say "I was bored tonight".

Name: Anonymous 2018-12-23 4:36

Haskell has this "and then we can eat their cat" vibe to it.

Name: Anonymous 2018-12-23 8:46

does it have dependent types?

Name: Anonymous 2018-12-23 15:22

>>2
Thanks for your kind words. Though, making a simple LISP or stack-based language is surprisingly easy - a feat that can be done in less than 2 hours if you are at least somewhat familiar with language design. I think that the complex syntax and the inconsistencies are what actually make implementation development for mainstream languages time consuming.

But what is your native language?
Greek, though I am somewhat ashamed to admit it. I am like Nikita (although much less crazy) in a way, where I don't really like or associate with most of my own kin.

>>4
It has dynamic type checking and its only types are "integers" and "functions" - similar to forth/postscript. That being said, making a A STLC/System F (and potentially dependently typed) stacklang sounds quite interesting. [1 +] for example should have as its type something like \(Int \to Int\) and similarly dup should have something like \(\forall\ t.\ t \to Pair\ t\ t\) as its type. That being said, you would (obviously) not be able to write non-terminating terms such as [dup eval] dup eval (which I think that it corresponds to \((\lambda\ x.\ x\ x)\ (\lambda\ x.\ x\ x)\)) with such a type system.

Name: Anonymous 2018-12-24 8:56

>>5
Greek, though I am somewhat ashamed to admit it.
But why? Greece is a civilized European country of great thinkers. Today Greece is known for talented musicians like Vangelis, Basil Poledouris and Yiannis Chryssomallis. It is incomparable with Russia.

Name: Anonymous 2018-12-24 11:20

These posts show we really need to decentralize everything even if not seemingly bad, but for the fact that any one person can effect their will.

If you build software, push forward.

Name: Anonymous 2018-12-24 13:17

>>6
Greece is a civilized European country of great thinkers
While some smart and good individuals do indeed to exist in Greece sadly the majority of the population does not fit said description. As for the country itself, I would argue that it is barely better than 3rd world countries (something that I think applies to most Balkan countries). Corruption everywhere, dogpoop on the sidewalks, sidewalks being wide enough only for a single chicken to pass through, cars and motorcycles being parked on the sidewalks without the police doing anything, shitty healthcare insurance that does not even compare to say NHS (though admittedly the service provided by the hospitals is not that bad), single-parent families having to actually pay for the extra income that multiple-children families receive, multiple anti-free speech laws <example: https://yro.slashdot.org/story/12/09/25/1649223/>, and Greek education (including universities) being a nightmarish joke are some of the issues that surround Greece.

Even the CS book that high school students aiming to get to a Greek uni should read contains claims such as "bubble-sort is the slowest sorting algorithm while quick-sort is the fastest", has dumb OOP propaganda, and teaches a translated pascal variant that only has non-free implementations and works only on windows.

Today Greece is known for talented musicians like Vangelis, Basil Poledouris and Yiannis Chryssomallis
Not J-pop.

>>7
I am not sure what you mean. Would you mind elaborating?

Name: Anonymous 2018-12-24 13:36

>>8
Not J-pop.
Fucking weeaboo

Name: Anonymous 2018-12-24 13:54

>>8
Would you mind elaborating?
I was driving home in my BMW when I heard the news. I pulled over to the side of the road and wept for 10 solid minutes. I've never done that. Not even when my parents died. I'm a broken man. I tried to warn you.

The decentralization of the internet has to happen ASAP.

Name: Anonymous 2018-12-24 14:29

Please rate my dubs

Name: Anonymous 2018-12-24 14:31

>>11
11/10

Name: Anonymous 2018-12-24 22:28

>>9
be nice

Name: Anonymous 2018-12-24 23:12

if it ain't Lisp

Name: Anonymous 2018-12-25 9:55


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List