Skip to content

Commit

Permalink
tmp(std,examples): remove err outport from For and Println
Browse files Browse the repository at this point in the history
  • Loading branch information
emil14 committed Nov 11, 2024
1 parent c61e720 commit 176cd12
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
24 changes: 9 additions & 15 deletions examples/99_bottles/main.neva
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
def Main(start) (stop) {
App, Panic
---
:start -> app
app:err -> panic
app:sig -> :stop
}
import { fmt }

def App(sig any) (sig any, err error) {
first For<int>{FirstLine}?
def Main(start any) (stop any) {
first For<int>{FirstLine}
dec Dec<int>
second For<int>{SecondLine}?
second For<int>{SecondLine}
wait Wait
---
:sig -> 99..-1 -> first -> dec -> second -> wait -> :sig
:start -> 99..-1 -> first -> dec -> second -> wait -> :stop
}

def FirstLine(data int) (sig any, err error) {
p1 Println, p2 Println, p3 Printf?
def FirstLine(data int) (sig any) {
p1 fmt.Println, p2 fmt.Println, p3 fmt.Printf?
---
:data -> switch {
0 -> { 'No more bottles of beer on the wall, no more bottles of beer.' -> p1 }
Expand All @@ -29,8 +23,8 @@ def FirstLine(data int) (sig any, err error) {
[p1, p2, p3] -> :sig
}

def SecondLine(data int) (sig any, err error) {
p1 Println, p2 Println, p3 Println, p4 Printf?
def SecondLine(data int) (sig any) {
p1 fmt.Println, p2 fmt.Println, p3 fmt.Println, p4 fmt.Printf?
---
:data -> switch {
-1 -> { 'Go to the store and buy some more, 99 bottles of beer on the wall.' -> p1 }
Expand Down
20 changes: 11 additions & 9 deletions std/builtin/streams.neva
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// basic stream operations
// --- Basic operations ---

// Wait blocks until last stream item arrive, then sends signal.
pub def Wait(data stream<any>) (sig) {
If
// Wait blocks until last stream item arrive, then sends a signal.
pub def Wait(data stream<any>) (sig any) {
Del
---
:data -> .last -> if
if:then -> :sig
:data -> .last -> switch {
true -> :sig
_ -> del
}
}

// ArrPortToStream iterates over all array-inport's slots in order
Expand Down Expand Up @@ -144,18 +146,18 @@ pub def Accumulator<T>(init T, upd T, last bool) (cur T, res T)
//
// Like other iterators, it processes items one at a time without blocking the stream.
// To wait for all items to be processed, use with `Wait`.
pub def For<T>(data stream<T>) (res stream<T>, err error) {
pub def For<T>(data stream<T>) (res stream<T>) {
first First
lock Lock<T>
handler IForEachHandler<T>?
handler IForEachHandler<T>
---
:data -> [lock:data, first]
[first:then, handler] -> lock:sig
lock:data -> .data -> handler
}

// IForEachHandler is a dependency for For.
pub interface IForEachHandler<T>(data T) (sig any, err error)
pub interface IForEachHandler<T>(data T) (sig any)

// `First` is a helper that allows to check if given stream item is the first one.
def First(data stream<any>) (then bool, else bool) {
Expand Down
3 changes: 2 additions & 1 deletion std/fmt/fmt.neva
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// TODO add err outport
// Println prints to the standard output with a newline.
#extern(println)
pub def Println<T>(data T) (sig struct{}, err error)
pub def Println<T>(data T) (sig struct{})

// Printf replaces `$` with the corresponding argument
// and prints to the standard output.
Expand Down

0 comments on commit 176cd12

Please sign in to comment.