LogicodeLang / Logicode

An esoteric language based on logic gates.
MIT License
12 stars 3 forks source link

Variables in circuits? #12

Closed hanyuone closed 8 years ago

hanyuone commented 8 years ago

I would like to suggest a new feature: variables in circuits.

They would work like this:

circ test(a,b)->[
  var in_circ=a&b
  in_circ+1
]
out test(1,1)

Which would then output 11.

somebody1234 commented 8 years ago

Oh yay more syntax, I'll work on it once I get back on by laptop.

Multiline circuits looks like the bigger feature here, once that's done it should work fine since circuits have their own scope anyway :P

hanyuone commented 8 years ago

While we're on the topic of improving syntax, this doesn't work:

a[t][h]

We should probably improve the parser so that this works.

I'll work on this bit - I just have no idea where to start.

bortkiewicz commented 8 years ago

Uh... isn't there a "command separator" like ; as in Python? This would make it easier because then everything can first be compressed to circ test(a,b)->var in_circ=a&b;in_circ+1. The parser would split it and recursively parse them.

And isn't there a "return command" to specify the parser WHAT to return from a circuit?

somebody1234 commented 8 years ago

@DerpfacePython Should be simple, I'll do it tomorrow @testitem That should parse as:

circ test(a,b)->var in_circ=a&b
in_circ+1

IMO

@DerpfacePython What do you think about having a command separator though?

bortkiewicz commented 8 years ago

Well the com sep shouldn't be as common as in C++ and like that, one-per-line

hanyuone commented 8 years ago

A command separator would be nice, but IMO we should have both multi-line functions and command separators.

bortkiewicz commented 8 years ago

Well MLFs could work by compressing the code block in the brackets.

somebody1234 commented 8 years ago

@DerpfacePython So we use ; for command separator?

hanyuone commented 8 years ago

@somebody1234 Ummm... yeah, sure, why not. I'm thinking of a better separator, though.

Maybe use | as a separator, change OR to ? and change the random bit to *?

somebody1234 commented 8 years ago

IDK, | is or in most languages, just change the regexes when you've decided

hanyuone commented 8 years ago

But ; seems really mainstream...

Also, conds aren't supported in circuits.

somebody1234 commented 8 years ago

@DerpfacePython Yeah, what about conds and circuits

hanyuone commented 8 years ago

So something like this:

circ asdf(a)->[
    var a=0+a[t]
    cond a->asdf(a)/0
]

returns a KeyError.

somebody1234 commented 8 years ago

Oh, you want conds, brb fixing

EDIT: @DerpfacePython should be fixed now

hanyuone commented 8 years ago

Also, [t] doesn't work - something like

var a=1110
out a[t]

outputs 0 instead of 110.

somebody1234 commented 8 years ago

@DerpfacePython Oh wait whoops

hanyuone commented 8 years ago

What? I thought [t] was all bits other than the 1st one.

somebody1234 commented 8 years ago

@DerpfacePython Sorry about that, will fix when I get home in ~3h

hanyuone commented 8 years ago

Nah, DW about the last problem - I fixed it.

somebody1234 commented 8 years ago

@DerpfacePython Actually fixed now