Please log in.
Before you can vote, you need to register. Please log in or create an account.
Computer: Programming Language
textual flowchart programming...   (-1)  [vote for, against]

Hmmmm...

usually we write normal C functions like this

out = some_func( input1, input2 );

Which usually implies fixed set of inputs and one result output.

But what if you want more than one output? Usually that is done via

some_func( input1, &out2 );

But when I draw mental graph of my programs its more like

---- Data input --->[ Black Box (param1, param2) ] --- Data output --->

So in C, when dealing with data flows... I sorta try to keep to that model via:

void func_name ( const int input, const int param, int *output);

But sometimes i want to avoid making new variables for ram savings... so

void func_name ( const int param, int *input_and_output);

-----

So if we have some way of expressing the concept of "data input" "const parameters" and "data output"... that would be cool.

int VarIn=1, Varout=0;

(VarIn)
|
|
V
funcA( param1, param2, param3 )
|
|
V
funcB( param1, param2, param3 )
|
|
V
(VarOut)

Obviously above example sucks, but it might get the point across of maybe thinking of a way to have a more flowcharty way of representing programming logic.
-- mofosyne, Dec 28 2016

Skov http://skov.software/en/
Flowchart-y language [Cuit_au_Four, Dec 28 2016]

Viskell https://github.com/viskell/viskell
Visual IDE for Haskell-like language [Cuit_au_Four, Dec 28 2016]

Literate programming https://en.wikipedi...iterate_programming
by Donald Knuth [notexactly, Dec 30 2016]

You can always declare some_func() as returning a pointer to a structure - that's simple and elegant and removes the need for declaring GLOBAL STATICs, which are clumsy and eat memory.

BCPL might be a better starting point than C, if you want to define your meta-language as a Chomsky syntax-free grammar.
-- 8th of 7, Dec 28 2016


// But what if you want more than one output?

Then return either a tuple or return a polymorphic type, if your language supports these things. If you're working in a C-like language, return a pointer to structure that has a type field. A function can only have one range. If your function returns apples for some inputs and oranges for other inputs, then its range is the union of apples and oranges (and possibly the null fruit). If it always returns one apple and one orange, then its range is the Cartesian product of apples and oranges.
-- Cuit_au_Four, Dec 28 2016


// return a pointer to structure that has a type field. //

We said that already. <points at first anno>

// null fruit //

They're pretty tasteless ...
-- 8th of 7, Dec 28 2016


yea i am aware of passing structs. just somehow not really satisfied about it.
-- mofosyne, Dec 28 2016


so... you want a variable to have more than one name ? easy enough in cobol ("rename"). C, I imagine you'd do something a bit more awkwardy with pointers or structs. still not complicated, though.
-- FlyingToaster, Dec 28 2016


> if idea = other: [general] / then CATEGORY SELECT invalid ...
-- normzone, Dec 28 2016


The idea's more about a way of describing data flow paths, rather than the actual mechanism.
-- 8th of 7, Dec 28 2016


In the MS world, Workflow Foundation lets you do this sort of thing ... so long as you don't mind race conditions in the build process, and suchlike MS-y features.
-- pertinax, Dec 29 2016


// ErrorEnum = func( in a, in b, in c, out x, out y, out z) //

In Blue Book C that only works if out x, out y, out z are GLOBAL STATIC, or passed as pointers to variables within the calling function. You can't dynamically return an rvalue via a function call argument.

Besides, unless the variables are big structures, arrays, or strings, why worry about RAM usage ? Is this an embedded application - if so, is C the right tool for the job ?

Hand-coded assembler will beat the best optimising compiler every time. Just enjoy the debugging ...
-- 8th of 7, Dec 29 2016


This reminds me of two things: the function definition syntax used in Haskell and similar functional languages, and literate programming [link].
-- notexactly, Dec 30 2016


Eh, you really gotta understand that cost is still a factor in getting more ram in embedded programming.

Also perhaps rust has an interesting way of dealing with "input output" declaration, via ownership transfer. Because the issue with C, is if you create a working variable, but it gets scoped out when you return the pointer to it (upon end of that function).

(Though admittedly transfer of ownership doesn't enforce not changing the input in rust).
-- mofosyne, Dec 30 2016



random, halfbakery