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.
 
  • Post
  • Reply
jony neuemonic
Nov 13, 2009

http://gigamonkeys.com/book/numbers-characters-and-strings.html :toot:

quote:

One of the reasons Lisp is a nice language for math is its numbers behave more like true mathematical numbers than the approximations of numbers that are easy to implement in finite computer hardware. For instance, integers in Common Lisp can be almost arbitrarily large rather than being limited by the size of a machine word. And dividing two integers results in an exact ratio, not a truncated value. And since ratios are represented as pairs of arbitrarily sized integers, ratios can represent arbitrarily precise fractions.

On the other hand, for high-performance numeric programming, you may be willing to trade the exactitude of rationals for the speed offered by using the hardware's underlying floating-point operations. So, Common Lisp also offers several types of floating-point numbers, which are mapped by the implementation to the appropriate hardware-supported floating-point representations. Floats are also used to represent the results of a computation whose true mathematical value would be an irrational number.

Finally, Common Lisp supports complex numbers--the numbers that result from doing things such as taking square roots and logarithms of negative numbers. The Common Lisp standard even goes so far as to specify the principal values and branch cuts for irrational and transcendental functions on the complex domain.

Adbot
ADBOT LOVES YOU

JawnV6
Jul 4, 2004

So hot ...
my friend, have you heard of the glory of unums?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
how do i represent a non-rational real value like sqrt2 or pi in common lisp

jony neuemonic
Nov 13, 2009

a big float, i guess

paging eschaton, we need a way better lisp nerd than me in here.

fritz
Jul 26, 2003

Suspicious Dish posted:

how do i represent a non-rational real value like sqrt2 or pi in common lisp

a lazily evaluated chebyshev series

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

fritz posted:

a lazily evaluated chebyshev series

algebraic numbers are ez u just compute in the correct field extension of Q. u can then extend this by stapling on e and pi and poo poo


chebfun is cool but inexact at heart

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

jony neuemonic posted:

a big float, i guess

paging eschaton, we need a way better lisp nerd than me in here.

or a big rational, say 314159265358979/100000000000000, which lets you choose a precision instead of having it dictated by where the value falls in the floating point range. but yeah lisp uses floats

fritz posted:

a lazily evaluated chebyshev series

more likely than you think! there are libraries that do this

e: lazy evaluations of approximations I mean, not specifically a chebyshev series (which I confused with the taylor series because I'm bad at math)

hackbunny fucked around with this message at 21:58 on Aug 1, 2016

Athas
Aug 6, 2007

fuck that joker

No, this is exactly the crap that makes for a lovely compiler target. Python has bignums too. But if I have a language that has an "8 bit integer" type, programs in the language that depends on overflowing behaviour for correctness, then I get the joy of packing it in a Numpy or ctypes int8 class if I want to target Python.

What a human wants in the language is not necessarily what a code generator wants.

I do remember something about Common Lisp supporting some strange user-defined modular arithmetic types, but I'm hazy on the details. Common Lisp has so much weird crap that nobody asks for (displaced arrays yay).

minidracula
Dec 22, 2007

boo woo boo

JawnV6 posted:

my friend, have you heard of the glory of unums?
Heh. I have, but I admit I haven't bought his CRC Press book yet. In any format.

JawnV6
Jul 4, 2004

So hot ...

rjmccall posted:

if you're not checking types, but are just rewriting source structures to similar structures in the target language, what you have is not a "compiler" because you aren't really implementing the source language
ah, right, that's how he defined "compiler" to begin with, which sorta seemed odd


anyway I literally can't stop reading this guy. today's entry almost garners praise for staving off type mysticism until the first value bullet point, but the abstract implies it's one of two points of comparison between langs along with 'efficiency'. i personally didn't understand that languages should be providing ASLR, but i only made it to bronze palm

Sweeper
Nov 29, 2007
The Joe Buck of Posting
Dinosaur Gum
tcp is the worst it has too many magical config options udp for life

Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'

Sweeper posted:

tcp is the worst it has too many magical config options udp for life

ecn bithc

Space Whale
Nov 6, 2014
Does JavaScript just lend itself to or even encourage globals and sloppiness?

When I'm using compiled languages I'm almost always giving a called method from the caller everything it needs to know to do what it needs to do EXPLICITLY. JavaScript likes closures and just grabbing variables that aren't passed as parameters, it seems, and there's a big pile of globals I can't even loving find the definitions of text searching every source file in the project I'm fixing up right now.

Is this idiomatic or more symptomatic?

JFC there's a big script tag with globals injected by .NET MVC that the app uses:

code:
    isDebug = @HttpContext.Current.IsDebuggingEnabled.ToString().ToLower();
    BARNumber = '@ViewBag.BARNumber';
    currentUser = '@User.Identity.Name';
    currentRole = '@(User.IsInRole(AppName.RolesEnum.Admin.ToString()) ? AppName.RolesEnum.Admin.ToString() :
                  @User.IsInRole(AppName.RolesEnum.FOO.ToString()) ? AppName.RolesEnum.FOO.ToString() :
               @User.IsInRole(AppName.RolesEnum.Sales.ToString()) ? AppName.RolesEnum.Sales.ToString() : "N/A")';
    authenticationSource = '@User.Identity.AuthenticationType';
    isAdmin = ('@User.IsInRole(AppName.RolesEnum.Admin.ToString())' === 'True');
    isElevatedAdmin = false;
    isFOO = ('@User.IsInRole(AppName.RolesEnum.FOO.ToString())' === 'True');
    isSales = ('@User.IsInRole(AppName.RolesEnum.Sales.ToString())' === 'True');
Am I just a retard here (yes of course) or is this actually bad or what is going on :(

Space Whale fucked around with this message at 17:32 on Aug 11, 2016

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
javascript in a web browser starts with a big bundle of global state, so it probably does give people the wrong idea about that being a reasonable way to write programs

i don't know what your beef with closures is, though

Space Whale
Nov 6, 2014

rjmccall posted:

javascript in a web browser starts with a big bundle of global state, so it probably does give people the wrong idea about that being a reasonable way to write programs

i don't know what your beef with closures is, though

I just like being able to look at the argument list of a function/method, probably because I'm really more of a C# guy.

The thought of "just being there" instead of explicitly passed down makes me grunt.

There's a good chance I'm not using the right terminology or just full of poo poo.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Space Whale posted:

The thought of "just being there" instead of explicitly passed down makes me grunt.

it's not that different from members

Shaggar
Apr 26, 2006

Space Whale posted:

Does JavaScript just lend itself to or even encourage globals and sloppiness?

When I'm using compiled languages I'm almost always giving a called method from the caller everything it needs to know to do what it needs to do EXPLICITLY. JavaScript likes closures and just grabbing variables that aren't passed as parameters, it seems, and there's a big pile of globals I can't even loving find the definitions of text searching every source file in the project I'm fixing up right now.

Is this idiomatic or more symptomatic?

JFC there's a big script tag with globals injected by .NET MVC that the app uses:

code:
    isDebug = @HttpContext.Current.IsDebuggingEnabled.ToString().ToLower();
    BARNumber = '@ViewBag.BARNumber';
    currentUser = '@User.Identity.Name';
    currentRole = '@(User.IsInRole(AppName.RolesEnum.Admin.ToString()) ? AppName.RolesEnum.Admin.ToString() :
                  @User.IsInRole(AppName.RolesEnum.FOO.ToString()) ? AppName.RolesEnum.FOO.ToString() :
               @User.IsInRole(AppName.RolesEnum.Sales.ToString()) ? AppName.RolesEnum.Sales.ToString() : "N/A")';
    authenticationSource = '@User.Identity.AuthenticationType';
    isAdmin = ('@User.IsInRole(AppName.RolesEnum.Admin.ToString())' === 'True');
    isElevatedAdmin = false;
    isFOO = ('@User.IsInRole(AppName.RolesEnum.FOO.ToString())' === 'True');
    isSales = ('@User.IsInRole(AppName.RolesEnum.Sales.ToString())' === 'True');
Am I just a retard here (yes of course) or is this actually bad or what is going on :(

the MVC stuff there is all request variables. ex: User.Identity.Name is the current request's user's name. It would be nicer to put the logic of currentRole, isAdmin, etc... into a viewmodel instead of in the view like this, but none of this is really too bad.

This would be a problem if A) the resulting javascript variables are used for security purposes client side instead of just display or B) the returned view is being used as a partial that will be referenced over and over thru multiple requests (like in an SPA).

It would be cleaner to maybe return these things as json or as a javascript module to keep it out of the javascript globals but then again its javascript and garbage is standard operating procedure.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Space Whale posted:

There's a good chance I'm just full of poo poo.

its this, op

closures are an abstraction tool and a good way of separating things into independently reusable and testable components

also they exist in c#, so you do not actually have an excuse

Shaggar
Apr 26, 2006
closures are stupid bullshit for when you're in a language with bad type support.

qntm
Jun 17, 2009
closures with explicit capture are pretty good

Zaxxon
Feb 14, 2004

Wir Tanzen Mekanik

Shaggar posted:

closures are stupid bullshit for when you're in a language with bad type support.

what does it have to do with types?

Space Whale
Nov 6, 2014

rjmccall posted:

its this, op

closures are an abstraction tool and a good way of separating things into independently reusable and testable components

also they exist in c#, so you do not actually have an excuse

Linq is one thing, but having a method that just grabs a variable that wasn't passed in makes me go "where the hell is it getting fooThing from?"

With a linq closure (that is a closure, right?) it's an anonymous inlined method that's literally right there, not just expecting a variable with that name to be in scope when it's called.

Right?

Space Whale
Nov 6, 2014

Shaggar posted:

closures are stupid bullshit for when you're in a language with bad type support.

Isn't LINQ all about closures though?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Space Whale posted:

Linq is one thing, but having a method that just grabs a variable that wasn't passed in makes me go "where the hell is it getting fooThing from?"

With a linq closure (that is a closure, right?) it's an anonymous inlined method that's literally right there, not just expecting a variable with that name to be in scope when it's called.

Right?

are you talking about dynamic scoping or something, because that doesn't exist in javascript. the javascript scoping rules are weird and evil, lookups just resolve to properties of the global object, but that has nothing to do with closures

closures are when you have nested objects/functions that capture ("close over") local variables that are in scope. linq makes some closures implicitly but delegates and lambdas are the general features

Space Whale
Nov 6, 2014
Now that I look harder at it, I think it's just "globals everywhere" and I was confused as poo poo. I'm also a crybaby because I've avoided doing serious JS for years and I'm finally dealing with it.

I'm still mad though. Offshored poo poo being used by a pretty major isp that you might be on right now? I'm fixing it. It's tooling for analysts, not infrastructure stuff, if that makes you feel better.

AWWNAW
Dec 30, 2008

the only time I shake my limp-wristed fist at closures is when i have to refactor out a nested function and figure out what all context it's capturing so i can add it as arguments

Space Whale
Nov 6, 2014
Always be explicit :q:

VikingofRock
Aug 24, 2008




Higher-order functions suck without closures, and higher-order functions are very good, therefore closures are very good.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Space Whale posted:

I've avoided doing serious JS for years and I'm finally dealing with it.

this should help you get started:

JavaScript code:
(function() {
"use strict";

// put all your code here

}());

Sapozhnik
Jan 2, 2005

Nap Ghost
javascript definitely feels like a "closures are a poor man's objects" lang as opposed to the other way around.

comedyblissoption
Mar 15, 2006

Space Whale posted:

Does JavaScript just lend itself to or even encourage globals and sloppiness?
virtually all mainstream langs encourage this imo

people like to pretend they dont have global mutable state by putting little pretty curtains around it

skimothy milkerson
Nov 19, 2006

did anyone say pjavascript yet?

hobbesmaster
Jan 28, 2008

comedyblissoption posted:

virtually all mainstream langs encourage this imo

people like to pretend they dont have global mutable state by putting little pretty curtains around it

likewise all control statements are no better than gotos

Volte
Oct 4, 2004

woosh woosh

comedyblissoption posted:

virtually all mainstream langs encourage this imo

people like to pretend they dont have global mutable state by putting little pretty curtains around it
the curtains are what makes it not global

Volte
Oct 4, 2004

woosh woosh
we're all naked under our clothes man

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Volte posted:

we're all naked under our clothes man

deep

comedyblissoption
Mar 15, 2006

the sane way to structure the vast majority of programs is probably glueing together mutable state transformations with pure-enough functions where the pure-enough functions make up most of the program

most mainstream langs dont really encourage the above

comedyblissoption
Mar 15, 2006

if you have a globally mutable variable but you put it inside an effectively singleton class and dependency inject the state, somehow it's no longer a global variable

Volte
Oct 4, 2004

woosh woosh
if you are using singletons with mutable state inside them then you've hosed up already

Adbot
ADBOT LOVES YOU

comedyblissoption
Mar 15, 2006

dependency injection frameworks let you pretend singletons arent singletons

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply