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
Cybernetic Vermin
Apr 18, 2005

cl is one of the best language standardization efforts ever, but it is still pretty much a dead end and the ecosystem is still fractured. clisp is the wrong place to start, sbcl is more workable, but just going with the free version of allegro common lisp is probably the best bet if your loving around doesn't require open source. Practical Common Lisp is actually a really well written and pragmatic book http://www.gigamonkeys.com/book/

Adbot
ADBOT LOVES YOU

~Coxy
Dec 9, 2003

R.I.P. Inter-OS Sass - b.2000AD d.2003AD

MeramJert posted:

this is yet another american thing though. other places use grams and it's way better

nah not necessarily british/australian recipes all use cups too

Workaday Wizard
Oct 23, 2009

by Pragmatica
what's the advantage of lisp over haskell? i don't know either very well (did euler project problems in haskell, never touched lisp)

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

~Coxy posted:

nah not necessarily british/australian recipes all use cups too

oh, well i guess i havent seen many of those. apparently its an anglophone problem

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

Shinku ABOOKEN posted:

what's the advantage of lisp over haskell? i don't know either very well (did euler project problems in haskell, never touched lisp)

theyre hardly comparable, really

Cybernetic Vermin
Apr 18, 2005

Shinku ABOOKEN posted:

what's the advantage of lisp over haskell? i don't know either very well (did euler project problems in haskell, never touched lisp)

common lisp is very much multi-paradigm, the object system is actually very good, though weird from the java perspective. classic lisp tomfoolery with syntax is also a big part. being an ansi standard with a bunch of implementations (with support and so on) is also an advantage, though i think the sort of market appeal side of thing is silly for both cl and haskell since neither is about to burst onto the scene and grab any real market share

Pie Colony
Dec 8, 2006
I AM SUCH A FUCKUP THAT I CAN'T EVEN POST IN AN E/N THREAD I STARTED
lisp is a lot simpler

Assepoester
Jul 18, 2004
Probation
Can't post for 10 years!
Melman v2

Pie Colony posted:

lisp (is (a ((lot) simpler)))

MononcQc
May 29, 2007

'(lisp is a lot simpler)

Soricidus
Oct 21, 2010
freedom-hating statist shill

~Coxy posted:

nah not necessarily british/australian recipes all use cups too
nope

british recipes use ounces or grams (often both are given). even fluids are measured in fluid ounces, pints, or millilitres, but never cups.

Nomnom Cookie
Aug 30, 2009



Luigi Thirty posted:

i recently discovered lisp and it seems pee cool to mess around with but how do i make it talk to a mysql? there's like five zillion libraries with lovely documentation and they all don't work unless you have a specific lisp implementation pirated from a DEC backup disc in 1975 or whatever the gently caress. i'm just using whatever apt-get install clisp downloaded i ain't got time for that jibba jabba

now u know why no one uses lisp

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band
i write so little code these days that when i do have to hack out a script, simple things get my brain twisted every which way. i just need to loop over a list of strings, run a command on each one, and retry that command x times or until it succeeds (whichever comes first). first i'll try "while true" and break out of that when i'm done; then i decide it would be better to just have a for loop that runs as many times as you've set the retry to or until the thing succeeds; then i think maybe the most "elegant" way to do it is something functional involving recursion. i tell myself i need to stop trying to be clever and/or elegant, but i can imagine the shame if i do something "wrong" and some real developer sees it. they're all gonna laugh at me

i wasn't always this stupid, honest :negative:

gonadic io
Feb 16, 2011

>>=
option paralysis is a thing, lots of people (including myself) suffer from it

assuming you're using python or whatever, a for-loop using break when it succeeds is probably the way I'd do it (TCO :arghfist:)
code:
def tryNTimes(f, n):
    for _ in xrange(0,n):
        if f():
            break
in haskell absolutely use recursion - off the top of my head
code:
tryNTimes _ n | n <= 0 = return False
tryNTimes f !n = do
    succeeded <- f
    if succeeded then return True
         else tryNTimes f (n-1)

weird
Jun 4, 2012

by zen death robot

AlsoD posted:

code:
tryNTimes _ n | n <= 0 = return False
tryNTimes f !n = do
    succeeded <- f
    if succeeded then return True
         else tryNTimes f (n-1)

what does the ! in the pattern mean ?

gonadic io
Feb 16, 2011

>>=

apt gangbang posted:

what does the ! in the pattern mean ?

it means that n is strict i.e. is evaluated immediately. actually the ! should be in the first line rather than the second but whatever. making accumulator variables strict is important to stop memory leaks

e: poo poo it's not even needed since you're checking if it's <= 0 anyway. ~laziness~

gonadic io fucked around with this message at 23:11 on May 22, 2014

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

AlsoD posted:

option paralysis is a thing, lots of people (including myself) suffer from it

assuming you're using python or whatever, a for-loop using break when it succeeds is probably the way I'd do it (TCO :arghfist:)
code:
def tryNTimes(f, n):
    for _ in xrange(0,n):
        if f():
            break

this is python, in fact -- i'll give that one a shot. looks straightforward :tipshat:

gonadic io
Feb 16, 2011

>>=
it's also pretty easy to modify it to return whether or not it succeeded (True or False) or now many tries it took (None if it never succeeded else some int) depending on your needs

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

prefect posted:

i write so little code these days that when i do have to hack out a script, simple things get my brain twisted every which way. i just need to loop over a list of strings, run a command on each one, and retry that command x times or until it succeeds (whichever comes first). first i'll try "while true" and break out of that when i'm done; then i decide it would be better to just have a for loop that runs as many times as you've set the retry to or until the thing succeeds; then i think maybe the most "elegant" way to do it is something functional involving recursion. i tell myself i need to stop trying to be clever and/or elegant, but i can imagine the shame if i do something "wrong" and some real developer sees it. they're all gonna laugh at me

i wasn't always this stupid, honest :negative:

I used to overthink a lot this kind of stuff. I guess I got better when I started to regularly do problems.

Like I'm pretty sure I won't be able to find the most elegant way to do it right away, but I'll get the obvious non-dumb way first for sure. I dunno, after solving 2105152 trivial fizzbuzzes you get some results of your previous overthinking cached in your mind.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Symbolic Butt posted:

I used to overthink a lot this kind of stuff. I guess I got better when I started to regularly do problems.

Like I'm pretty sure I won't be able to find the most elegant way to do it right away, but I'll get the obvious non-dumb way first for sure. I dunno, after solving 2105152 trivial fizzbuzzes you get some results of your previous overthinking cached in your mind.

unsurprisingly, this applies to pretty much every creative process

Bloody
Mar 3, 2013

var res = String.join(Array.reverse(str.split(' ')));

i think

wait is this not the thread where we were janitoring strings?

whatever :justpost:

gonadic io
Feb 16, 2011

>>=
Array.reverse returns void

also you need String.join (" ", ...) instead but whatever

e: :arghfist:

all programmers are terrible anyway

Bloody
Mar 3, 2013

eh w/e close enough considering i missed the right thread

c#'d at least be nice enough to tell me that was wrong :) who nkwos what java script or php wouldve done probably farted out an ugly string of garbage tho

Nomnom Cookie
Aug 30, 2009



web devs call it html

Valeyard
Mar 30, 2012


Grimey Drawer
i cant do anything in javascrapt except use jquery

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Valeyard posted:

my cups are fuckin hugee loll, :greenangel:

gynocomastia that bad huh?

Valeyard
Mar 30, 2012


Grimey Drawer

carry on then posted:

gynocomastia that bad huh?

lol

Zombywuf
Mar 29, 2008

AlsoD posted:

option paralysis is a thing, lots of people (including myself) suffer from it

assuming you're using python or whatever, a for-loop using break when it succeeds is probably the way I'd do it (TCO :arghfist:)
code:
def tryNTimes(f, n):
    for _ in xrange(0,n):
        if f():
            break

In Python this is absolutely the way to do it, so much so that Python has the for else construct, really useful for finding the first thing that passes some requirement:
code:
for thing in things:
    if test(thing):
        break
else:
    raise IGotNothing()

do_stuff_here(thing)

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
I'll admit that I only use for else when I'm feeling like an rear end in a top hat because the most common thing to do is to just use some flag variable. pretty sure it doesn't slow down the code in any significant way.

I think I read somewhere that Knuth came up with this construct in response to covering every use case for goto. thanks knuth

tef
May 30, 2004

-> some l-system crap ->
i found myself using any() and all() with a generator comprehension over for-else

tef
May 30, 2004

-> some l-system crap ->
i.e.

if any(thing(x) for x in things):
....


if all(f(i) for i in range(n))
....

Notorious b.s.d.
Jan 25, 2003

by Reene

tef posted:

i.e.

if any(thing(x) for x in things):
....


if all(f(i) for i in range(n))
....

this is rad and makes me hate python just a little bit less

tef
May 30, 2004

-> some l-system crap ->

Notorious b.s.d. posted:

this is rad and makes me hate python just a little bit less

i kinda wish they'd removed for-else. if anything, for-then would be a better name for the semantics it has.

i always expected to have for-else in python work like: for .. else if there are zero elements, .....

and not for ... else if no break

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
Raymond Hettinger is a huge proponent of for-else, I was thinking about it and there's this example in his slides:

https://speakerdeck.com/pyconslides/transforming-code-into-beautiful-idiomatic-python-by-raymond-hettinger-1?slide=11

and you can still use a comprehension here instead of for-else, because comprehensions are loving awesome

Python code:
def find(seq, target):
    return next((i
                 for i, value in enumerate(seq)
                 if value == target), -1)
(please don't discuss again how terrible my indentation is)

weird
Jun 4, 2012

by zen death robot
why isnt ocaml's map tail recursive

Bloody
Mar 3, 2013

for else looks gross

MononcQc
May 29, 2007

apt gangbang posted:

why isnt ocaml's map tail recursive

for most map operations on lists and whatever finite data structure, no matter the language (as long as it's immutable and strict), it may be faster to use a body-recursive version.

Basically, the cost on stack will likely be little more than the duplication of pointers for the function you're using to map, and the pointer to the data structure you're mapping over. The data structure you're passing in basically limits how deep the stack goes. So you get two lists: the original one, and the mapped one. You've had an overhead of a couple pointers per list element to go with it, along with wherever the function returns.

OTOH, a tail recursive map will need to generate a second list anyway, and do it in a reverse-manner by prepending to the head of the list if immutable, to avoid the cost of rewriting the list on every traversal.
The end-result of this is that you then need to reverse the list at the end, creating a total of 3 lists: the original one, the intermediary one, and the final one (reversed intermediary).

The tail-recursive map may overall have required more memory than the body-recursive one, potentially triggering GC and whatnot.

That's super dependent on the language and its implementation, of course, but there are definite cases where a tail-recursive map can be seen as worse than a body-recursive one. You can benchmark them under different circumstances and see.

Soricidus
Oct 21, 2010
freedom-hating statist shill
if you need a tail-recursive map in ocaml, get extlib, which includes a drop-in tail-recursive replacement with no performance penalty.

(it avoids having to build the list backwards and reverse it by using a mutable data structure with the same memory representation as a list and then subverting the type system to turn it into one. don't try this at home.)

Zombywuf
Mar 29, 2008

tef posted:

i.e.

if any(thing(x) for x in things):
....


if all(f(i) for i in range(n))
....

Doesn't give you access to x though, also means you can't log. I like for else, it makes perfect sense to me.

gonadic io
Feb 16, 2011

>>=

Soricidus posted:

if you need a tail-recursive map in ocaml, get extlib, which includes a drop-in tail-recursive replacement with no performance penalty.

(it avoids having to build the list backwards and reverse it by using a mutable data structure with the same memory representation as a list and then subverting the type system to turn it into one. don't try this at home.)

unsafeCoerce is the best coerce

Adbot
ADBOT LOVES YOU

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

Zombywuf posted:

In Python this is absolutely the way to do it, so much so that Python has the for else construct, really useful for finding the first thing that passes some requirement:
code:
for thing in things:
    if test(thing):
        break
else:
    raise IGotNothing()

do_stuff_here(thing)

i had not been aware of this -- it feels weird to me (and it really makes me wish there were curly braces to organize this stuff), but it looks super-useful :tipshat:

tef posted:

i.e.

if any(thing(x) for x in things):
....


if all(f(i) for i in range(n))
....

i don't think this would work for what i'm trying to do (what i've done, actually -- once i put my head down and picked a way to do it, it came together (ugly, but functional)), since i want to execute a command only until it succeeds. would "if any(thing(x) for x in things)" execute the command even after a successful attempt?

  • Locked thread