Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
leftist heap
Feb 28, 2013

Fun Shoe
good god lens tutorials are the new monad tutorials

Adbot
ADBOT LOVES YOU

gonadic io
Feb 16, 2011

>>=

rrrrrrrrrrrt posted:

lol, lens defense incoming!!

cba, can somebody else say that yes those operators are excessive but they kinda make sense as a dsl?

gonadic io
Feb 16, 2011

>>=

rrrrrrrrrrrt posted:

good god lens tutorials are the new monad tutorials

and no, still plenty of new monad burrito "they make so much sense to me now!" tutorials appearing :(

leftist heap
Feb 28, 2013

Fun Shoe

gonadic io posted:

cba, can somebody else say that yes those operators are excessive but they kinda make sense as a dsl?

I had you in mind when I wrote that.






Shameful.

brap
Aug 23, 2004

Grimey Drawer

VikingofRock posted:

Isn't next() is doing the same thing as dereferencing it?

you're making an assumption that inside the Iterator there is a chunk of memory and a pointer referencing a location in the memory, but an iterator could be doing anything to obtain the next element in its sequence.

code:
    class Fiberator implements Iterator<Integer> {
        private int secPrev = 0;
        private int prev = 0;
    
        public boolean hasNext() { return true; }
        public Integer next() {
            if (prev == 0) {
                prev = 1;
                return 1;
            }
            int current = secPrev + prev;
            secPrev = prev;
            prev = current;
            return current;
        }
        public void remove() {
            ;
        }
    }
I probably belong in this thread as well

gonadic io
Feb 16, 2011

>>=

rrrrrrrrrrrt posted:

I had you in mind when I wrote that.






Shameful.

i know, who else would do it?

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
i cant decide whether it's an important difference in the java iterator interface vs the c# enumerator interface that the enumerator interface has MoveNext and Current, while the iterator interface just has next, so you can access the current value more than once with an IEnumerator

i guess it'd be easier to implement infinite sequences that conform to the java interface and it's not like it's a big deal that your calling code has to define the temp variable if it wants it

fritz
Jul 26, 2003


its true

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
also idk if i would have put remove() on that interface and not on some other interface, FullAccessIterator or somesuch

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

fleshweasel posted:

you're making an assumption that inside the Iterator there is a chunk of memory and a pointer referencing a location in the memory, but an iterator could be doing anything to obtain the next element in its sequence.

code:
    class Fiberator implements Iterator<Integer> {
        private int secPrev = 0;
        private int prev = 0;
    
        public boolean hasNext() { return true; }
        public Integer next() {
            if (prev == 0) {
                prev = 1;
                return 1;
            }
            int current = secPrev + prev;
            secPrev = prev;
            prev = current;
            return current;
        }
        public void remove() {
            ;
        }
    }
I probably belong in this thread as well

you are in this case "pointing" to the chunk of memory designated by "prev", though

iterators do whatever they want when you increment them and return whatever they want when you dereference them, you can give those operations different names if you want but that's what they do

leftist heap
Feb 28, 2013

Fun Shoe

gonadic io posted:

i know, who else would do it?

tbf i think lens is really cool but most of those operators... goddamn. pretty indefensible imo. and "it makes sense if you use them all the time and memorize these simple mnemonics!" is not a good defense.

gonadic io
Feb 16, 2011

>>=

rrrrrrrrrrrt posted:

tbf i think lens is really cool but most of those operators... goddamn. pretty indefensible imo. and "it makes sense if you use them all the time and memorize these simple mnemonics!" is not a good defense.

the worst one i've ever actually used myself is <<>= which is basically the writer monad's tell function.

gonadic io fucked around with this message at 17:42 on Jun 24, 2015

gonadic io
Feb 16, 2011

>>=
current terrible programmer status: i'd like to thank this paper for including both pseudocode and an appendix with their actual code in. between the two im quite able to translate it into f#

VikingofRock
Aug 24, 2008




Dessert Rose posted:

you are in this case "pointing" to the chunk of memory designated by "prev", though

iterators do whatever they want when you increment them and return whatever they want when you dereference them, you can give those operations different names if you want but that's what they do

Yeah this is what I was trying to say; I was just saying it poorly.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Dessert Rose posted:

also idk if i would have put remove() on that interface and not on some other interface, FullAccessIterator or somesuch

FullSpectrumIterator

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
being able to define an entire iterator with a single method definition in c# is so amazing, like you don't have to janitor class definitions or state variables, just write the method that generates the next element and yield return it from the loop that you'd naturally write

VikingofRock
Aug 24, 2008




Dessert Rose posted:

being able to define an entire iterator with a single method definition in c# is so amazing, like you don't have to janitor class definitions or state variables, just write the method that generates the next element and yield return it from the loop that you'd naturally write

drat that sounds sick

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

VikingofRock posted:

drat that sounds sick

the canonical fibonacci example:

code:
public IEnumerable<int> fibSequence()
{
  int secPrev = 0;
  int prev = 1;
  yield return prev;
  while (true)
  {
    int cur = (secPrev + prev);
    secPrev = prev;
    prev = cur;
    yield return cur;
  }
}

MononcQc
May 29, 2007

FWIW, Python also does this too

code:
def fib():
    prev = 0
    prevn = 1
    while True:
        cur = prev + prevn
        prev, prevn = prevn, cur
        yield cur

>>> f = fib()
>>> next(f)
1
>>> next(f)
2
>>> next(f)
3
>>> next(f)
5
>>> next(f)
8

Valeyard
Mar 30, 2012


Grimey Drawer
That's cool

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

MononcQc posted:

FWIW, Python also does this too

code:
def fib():
    prev = 0
    prevn = 1
    while True:
        cur = prev + prevn
        prev, prevn = prevn, cur
        yield cur

>>> f = fib()
>>> next(f)
1
>>> next(f)
2
>>> next(f)
3
>>> next(f)
5
>>> next(f)
8

fyi you missed the first "1", it goes 1, 1, 2, 3 ...

MononcQc
May 29, 2007

Dessert Rose posted:

fyi you missed the first "1", it goes 1, 1, 2, 3 ...

yeah, but I decided not to care more; guessed iterators were important more than the rest here.

Here's the fixed one anyway:

code:
def fib():
    prev = 0
    prevn = 1
    yield prevn
    while True:
        cur = prev + prevn
        prev, prevn = prevn, cur
        yield cur

brap
Aug 23, 2004

Grimey Drawer
welcome... to the Fibonacci Zone

CPColin
Sep 9, 2003

Big ol' smile.
I am pleased to see that java.util.Iterator.remove() now has a default implementation that throws an UnsupportedOperationException.

Soricidus
Oct 21, 2010
freedom-hating statist shill
I literally don't think I have ever used remove() on an iterator, or seen any code that uses it, or seen any iterator implementations outside the stdlib that support it

MeruFM
Jul 27, 2010
one cannot imagine the depths of terrible programming

Bloody
Mar 3, 2013

i want to make a program like gofmt for another language. i have a bnf grammar of the language and a vague idea of the things i would need to write to make it. this is the sort of thing that functional languages and pattern matching are good at, right? im thinking this may be an istp to learn f# with.

Soricidus
Oct 21, 2010
freedom-hating statist shill
camlp4 is an interesting comparison (and being implemented for and in ocaml, it should be fairly close to the f# world)

basically it's a parser and pretty-printer, kinda like gofmt, except it also permits other kinds of transformation so it can also implement preprocessing, syntax extensions, etc

i've never looked at the implementation though so i don't know how hideous it is

(probably very)

JewKiller 3000
Nov 28, 2006

by Lowtax
as an ocaml programmer, i recommend staying away from camlp4. it is very complicated and you probably don't need it

if you're interested in source code formatting in the ocaml world check out ocp-indent

Zaxxon
Feb 14, 2004

Wir Tanzen Mekanik

Bloody posted:

i want to make a program like gofmt for another language. i have a bnf grammar of the language and a vague idea of the things i would need to write to make it. this is the sort of thing that functional languages and pattern matching are good at, right? im thinking this may be an istp to learn f# with.

seems like the kind of thing functional stuff would be good at. Might as well do the F# if you want to.

abigserve
Sep 13, 2009

this is a better avatar than what I had before

OldAlias posted:

it has a bad reputation. the main spots you'd go for perl knowledge are old as gently caress - design wise + if you aren't paying attention you're going to get advice from 15 years ago where people seemed to tolerate horseshit. perl is good at certain things and has been bludgeoned into other roles like any other plang. idk CPAN is at least sane to use.

Fair. It gets a lot of use still in the networking field to write scripts so I had to learn it and I like it!

VikingofRock
Aug 24, 2008




Bloody posted:

i want to make a program like gofmt for another language. i have a bnf grammar of the language and a vague idea of the things i would need to write to make it. this is the sort of thing that functional languages and pattern matching are good at, right? im thinking this may be an istp to learn f# with.

Sounds pretty reasonable. I can't speak for F#, but yeah functional languages tend to be good at stuff like that.

jony neuemonic
Nov 13, 2009

abigserve posted:

Fair. It gets a lot of use still in the networking field to write scripts so I had to learn it and I like it!

this is exactly perl's wheelhouse and it's still a good fit.

Soricidus
Oct 21, 2010
freedom-hating statist shill

JewKiller 3000 posted:

as an ocaml programmer, i recommend staying away from camlp4. it is very complicated and you probably don't need it

if you're interested in source code formatting in the ocaml world check out ocp-indent

fair enough, I haven't really done ocaml for years so I'm sure my opinions are a bit dated

do you actually get paid to ml?

suffix
Jul 27, 2013

Wheeee!

Dessert Rose posted:

i cant decide whether it's an important difference in the java iterator interface vs the c# enumerator interface that the enumerator interface has MoveNext and Current, while the iterator interface just has next, so you can access the current value more than once with an IEnumerator

i guess it'd be easier to implement infinite sequences that conform to the java interface and it's not like it's a big deal that your calling code has to define the temp variable if it wants it

i just give up every time i tr yto write a c++ iterator

afaict it's a terrible interface for anythig but iterating over an array

c++ also has weird rules for what can be initialized how, so it was hard to make temporary values with generic types iirc

bobbilljim
May 29, 2013

this christmas feels like the very first christmas to me
:shittydog::shittydog::shittydog:

Soricidus posted:

I literally don't think I have ever used remove() on an iterator, or seen any code that uses it, or seen any iterator implementations outside the stdlib that support it

it's not really very useful after about Java 1.5

i used it the other day though lol

Zlodo
Nov 25, 2006

suffix posted:

i just give up every time i tr yto write a c++ iterator

afaict it's a terrible interface for anythig but iterating over an array

c++ also has weird rules for what can be initialized how, so it was hard to make temporary values with generic types iirc

i usually cheat and instead of writing custom iterators i write a template function that iterate over whatever i need and calls a lambda given as parameter on each element, it's much easier and when you write the function call + the lambda it kinda looks like a custom for loop

ranges will make all that stuff easier: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4128.html

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
Crystal is really promising. i'm doing a web frontend for the docker daemon and in a couple days i've written

a) a bespoke routing thing
b) bespoke html templating
c) the docker client
d) bespoke logging thing
e) some of a file based storage thing for holding the state

(a lot of this stuff exists on github i'm sure but i'm just trying to use the stdlib for fun)

anyhow it's basically like using ruby except you can develop EVEN FASTER!! because typing makes your job easier. also macros own and are way better than dynamic bullshit.

it's got a little ways to go but it's really really good.

jony neuemonic
Nov 13, 2009

i'm not about to hate on anyone's choice of fuckaround language but if you want something vaguely ruby-like but better why not elixir?

Adbot
ADBOT LOVES YOU

leftist heap
Feb 28, 2013

Fun Shoe
crystal is statically typed, I guess

  • Locked thread