Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

LUA is FFOC

Name: Anonymous 2011-02-05 9:01

LUA is the toy language for those who enjoy the Forced Flushing Of L1/L2 Cache per operation. In fact, every operation causes several L2 cache misses during table look-ups, flushing both the L1 and L2 caches.

http://www.slideshare.net/hughreynolds/optimizing-lua-for-consoles-allen-murphy-microsoft

Enjoy your FFOC.

Name: Anonymous 2011-02-07 17:48

#define aif(type, p, t, f) {type it = p; if(it) do { t; } while(0); else do { f; } while (0);

aif(int, 2+3, printf("%d\n", it), printf("%d is not true.\n", it))

Name: code less, create more 2011-02-07 17:49


m:aif p t f -> if it:$p $t $f



(define-syntax-case (aif p t f) (with-literal stx (it) #'(let ((it p)) (if it t f))))

Name: Anonymous 2011-02-07 17:53

>>119
overuse of object oriented (OOP) constructs
>>117-118 doesn't use OOP.
incorrect usage of design patterns
>>117-118 doesn't use any design pattern.
overuse of OOP methods/functions/procedures
>>117-118 uses only the strict necessary.
declarative programming
>>117-118 does the same as >>114, if one it's considered bloated for this, the other will be too.
excessive loop unrolling
>>117-118 doesn't even use loops.
excessive use of multiple conditional If statements
See: declarative programming. It also uses just one if.
dead code
All the code is reachable.
redundant calculations
`it' is evaluated once.

Therefore your wrong bitch

Name: Anonymous 2011-02-07 17:56

>>122
So what? Mine is hygienic, enjoy your name clashes.

Name: Anonymous 2011-02-07 17:59

Pick one:

(m: (aif p t f) (if/bind it p t f))



(m(a . r)(if/bind it . r))



(define-aif!)



(d)


d

(note: they are all valid code, yes, even `d')

Name: Anonymous 2011-02-07 18:01

>>124
I dont have any clashes.

Name: Anonymous 2011-02-07 18:05

>>126

(define if 2)

Oops :(((

However, >>125
d
this is shorter than your bloated DSL.

Name: Anonymous 2011-02-07 18:05

>>125
>Pick one:
I already have time-tested defmacro. It's easy and powerful.

Name: Anonymous 2011-02-07 18:06

>>127
Stop butthurting. Go learn some Clojure, because Scheme is a history.

Name: Anonymous 2011-02-07 18:07

>>128
Mine is the fucking same, it's just hygienic. Also, d is shorter than your bloated macro.

Name: Anonymous 2011-02-07 18:07

>>129
Call me when they have hygienic macros.

Name: Anonymous 2011-02-07 18:10

>>130>>131
hygienic
Is it like type-safe in haskell? Never liked this pedantic stuff from academy.

Name: Anonymous 2011-02-07 18:23

dubs

Name: Anonymous 2011-02-07 18:27

>>132
Is it like type-safe in haskell?

So, you started whining about something you don't even know? Perfect.

(defmacro aif (p t f)
  `(let ((it ,p))
     (if it ,t ,f)))

; later...

(defun if (x) x)
(aif (if 2) it 3) ; expands to: (let ((it (if 2))) (if it it 3))
; but now if it's being shadowed by if!!!
; it doesn't work



(define-macro (aif p t f)
  #:capture it
  #'(let ((it p))
      (if it t f)))

; later...

(define (if x) x)
(aif (if 2) it 3)
; this expands to (let ((it (if 2))) (the-old-if it it 3))
; OMG IT WERKZ!!
; `if' it's just looked up in the scope of the macro definition!!

Name: Anonymous 2011-02-07 19:37

>>134
>(defun if (x) x)
But my `if` resides in package cl-user, and `aif` uses `if` from CL! I guess crappy academic Scheme just doesnt have packages, like CL and Clojure do.

Name: ve seen it before!!11 2011-02-07 19:40

hygienic
Sometimes, you’re on a team, and you’re busy banging out the code, and somebody comes up to your desk, coffee mug in hand, and starts rattling on about how if you use multi-threaded COM apartments, your app will be 34% sparklier, and it’s not even that hard, because he’s written a bunch of templates, and all you have to do is multiply-inherit from 17 of his templates, each taking an average of 4 arguments, and you barely even have to write the body of the function. It’s just a gigantic list of multiple-inheritance from different classes and hey, presto, multi-apartment threaded COM. And your eyes are swimming, and you have no friggin’ idea what this frigtard is talking about, but he just won’t go away, and even if he does go away, he’s just going back into his office to write more of his clever classes constructed entirely from multiple inheritance from templates, without a single implementation body at all, and it’s going to crash like crazy and you’re going to get paged at night to come in and try to figure it out because he’ll be at some goddamn “Design Patterns” meetup.

Name: Anonymous 2011-02-07 20:03

>>136
If he's writing code that he expects you to use but that code doesn't match the design spec, just tell him you're not going to bother with it until the spec is updated.

Name: Anonymous 2011-02-07 20:03

>>135
I guess crappy academic Scheme just doesnt have packages
It has
But my `if` resides in package cl-user, and `aif` uses `if` from CL!
Enjoy your name clashes and gensyms, ``faggot''.

Name: Anonymous 2011-02-08 6:59


                 _    _             __  __   ______   _   _                                         
                | |  | |           |  \/  | |  ____| | \ | |     /\                                 
                | |  | |           | \  / | | |__    |  \| |    /  \                                
                | |  | |           | |\/| | |  __|   | . ` |   / /\ \                               
                | |__| |           | |  | | | |____  | |\  |  / ____ \                              
                 \____/            |_|  |_| |______| |_| \_| /_/    \_\                             
                                                                                                    
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQWWWWWWWWm##BWW#8SvawQWWQQQQQQQQ
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQWZZ##ZZZZZXX22nnnnvvI?YdQQQQQQQQQ
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQWmm#ZXZXXXXSnnvvvvonvli|IWQQQQQQQQ
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQW##XSSSS2onnvvvvIvoovv|+++?HQWQQQQ
QQQQQQQQQQQQQQQQQQQQQQQQQQQQWWWmWWWWWWWWQQQQQQQQQQQQQQQQQQQQQQQQQWWX2oooo1llli|lillvvvvi|=:-:+{3WWQQ
QQQQQQQQQQQQQQQQQQQQQQQQQW#m####XX2X22oSX#WWWQQQQQQQQQQQQQQQQDX$W#nnn1vnli||+===-:=+i||l|=:.  =||VQW
QQQQQQQQQQQQQQQQQQQQQQQW###mZXXon1vvv2XZ#ZXZZ#mQQQQQQQQQQQQQAom#Xlliilvvlli==:. ...:==|||=:.   +v%3Q
QQQQQQQQQQQQQQQQQQQQQW#ZXSXSXYIllIvnoXXX#Z##mBWQQQQQQQWWWQQ#XW##e>+=|lvvli|+=:.. . ..;====;     -<l3
QQQQQQQQQQQQQQQQQQWWXX11no1Iilvlivvnoom#mWmmmQWQQQQQW##WWQEnW#B}--.;+iIvl|+=;.     . .;===;.     =|v
QQQQQQQQQQQQQQQQBXZn1lIvIiiii%||llvvmm#m#####WWQQQQW#Z#WWDvWXW}-. ..=|llii||=; .     :=+=||%v>.  -=I
QQQQQQQQQQQQQQW#1o1vlili|i||%=|i|ivXXX#U#ZZXmWQQQWm##X#mWoXX#Z>..  :aqgwo2lisi;.    .<vviilvY*i. .|>
QQQQQQQQQQQQQWGvvll||||=||||=+|=|ioSXZXXSSomQQQQWmm#XX#BGevv3Xz;=  vWWZYY}<vIns:  ..:i|++~-  ..  :|>
QQQQQQQQQQQQQZnli||=||=|+|===+==|vo#ZXS22S#WWQQWWW#XXXmWli<i3#hii. 3X(:/   -+l|..  :||: .        =|:
QQQQQQQQQQQQ#n}||+=;====;:::===|inZZXn2oXXXWBQWWWm#X2mWZii<i3Zmvn= -I:-     :iIsa>=vov:          |+.
QQQQQQQQQQQB2I||=:::=:::.:.:::=|i2XS1oXZXoX##Q#WWW#oX@1eii|IvX#ZXc  <i=,  . _vumQmqmmXa=___;.   .=| 
QQQQQQQQQW#oi|||=:::::.:.:.:.:=|vno1vXZonvommWQWQWXoW|<1=i|iivXXXc. -+1XuwosumQQWQWWW#Xov|i=    :== 
QQQQQQQQQWWhi|=:::=;:::=:::-:=|ilvnlnXnnwXZ#$WQQW#XXk>ic+i|i|lvXo1=   =vXmm##BBWWWWm#X2l|+|=   .;=` 
WWWWWBWW##XS>=;;=;;====::;:;:+||lIlinnomWS1oQWQQW#XX2s%l|Illi||Ioov=. :{Xm##ZmmW#USX1o1vi|+=  .;==  
mmmZZ#####Xn>=;;;:=++=.::=:=+|||i|||nq##X1ld#WWQB#XnhoiiivliI|+=nXov;  =3##X##m#ol+|lvnvv|==  .===  
XX#SXXXXZXqh>=;::==:::==:; :==||+||<dXZ21sdG#mQW#Xom#Silii><i||=v3mv|  .)XSX##ZXn|=:={2oivi=. .=== .
SX#X#ZXXX$mos==.==:::===: .:-=+==|=io*llvndnmWW##2XmZXXvIi=:|:=ii3mz+   +lvXX#21l=:::=+Ivvi>   =||..
1nClv211XX#Ssi;=|===|==;  .: :;=;==i||vXoSodZm#Z2d#X2XXes|==l:=vnmmX|   .<lvmZXc==:. .. -~<|:  -|=|.
1n2vvooooXZ2s=-=====|+=.:.:: ...:;=:in11nnXX#ZXoXZ21nnnzvivi|.<vXW#e=    =ldmmX}--:. .    :Ii.  ==:|
oXZXXXXX###mz====+.||+::=;:..   ::=<vlv1ndZm#2oXXXvInlvXsnvii=|I3WX1;    <vQWWQc  - .     :i|...;=;<
211vn1vnnoXmoi===+.=||:===..   ..:<><nvo#Z#m#oXSonvivvoXo2vvvvvnd#1v;    =vWWW#X;.        =i|=.:.:=<
ilivvlsvvXmmZs>=|===+|=:+;;.. .  .=ivnXSXXXmZnn2nnvInXZXenlvvInn3Sli;    -vWWWmXv;       .||ina...:<
iivvvlvIXZQW#1:+=-+=|+i;=;:.     :=<lnvXXnd#Xnn2o2nlnXolliiIliiil1||=     3#mW#X1=-..   .:||uQQ:::=<
liiivIvnqmW#Xl<%:.==|=|;.::... ...-|{Iv#XomUXodo22nin2ol>|+l||=++|++=;.    )UXXYl|==- -:,=iwQQW.%==|
l|lvvlvdUXSSeii> ==+>=+:=::.   .:.;=<|nXSo#Z2nXX22n|nnnI|==|=|====+=|=;.     ~^--     .<nnmWQQQ=S>|+
=iii|llvI{dSv=i` -.=`==+- .   .:.::=<lnSoZSe2nXXnXo|IloI=:;+==::::==+=:. .           :=il2XS$WW(nn||
|i|<%+<%v|vol==: ..:.=-`     ....;===|InnlIiooZ2vZXil|ni==:;=-.:.:+=+> .            .-:<nmXwuvIil1==
|=|%i+|=|<nl> .- .:..:    .. :..:=-.;=Iii++vnXXnvZ2Ii|v>=; :: .: ==|+;...            .:|nQmQWWmuuaii
==|i>={*}*I{> .  : :...: =: ..::: ..;<i+`:<vo2vInZnv|iv==.    . ..==== . ..          .:<dmQQWWmmmXXX
|||||=<>=iI%` .  : :..=;.= ..::.  . =+=:._vionvvX2ii=ii::.        ..-- . .         . .=idWQQWWWmm###
|++=+|=>:=v>:;     : :== : . +;.   --:.=|vIoonvo2ii>=||..         :: ._..           ..<n#QQQWWmBm##Z
<=|i%=i|iuci|:.     ..-. . . :i;.    .ivvivoonnnn=v=|==:..       .:. =..        .   .:vmmQQWWWWBm##X
|v1vavnI11*!*+=.  . ..      .:+==:.  :<vvonn1vlli=I+|-;.:        .- .=:.         ...:<X#WWQQQWmmm##Z
. -.::;===+++|+=     ....  .:==+|+=. :<vIlvviiiisi><| =..        . ..=:.    .  :..-::i<2X##WmWmm##ZZ
.......:::::=:;=:   .. .:::;::;:==vc -===|I>=ivil<:<|.::.   .     . ::. .  .  .  ..=v,="{vvYXX###XZX
   . .  .:...-.;+ .   ..=;:+===;;={p:.;;=%=.%Ill>===i::-. . ..   .  .:. - . . .:.:.:.""ns."+<I*1no2X
     . .. .. ..;=.    :::..- ..:-=3"`  ;|:=%lll>==>.|`: : :    . .   ::  .:.-..:::;     -?a,:^<i||{l
        - :.  -=;       :=. .-:.-.     ===Iii|++=+:==.     . ..;..    -  ::  ..;::.        "4a, -~|-
      .      .  .       .-:=          .+=|>|=|=;= =: .    .   .;..        .. .-::... .     .  "1a   
           .    -.          `        .=|+=|||===.=;:         .=;;.        . ..=:. .             -?s,

Name: Anonymous 2011-02-08 15:07

>>139
;_;
Why, Xarn-kun, why?

Name: Anonymous 2011-02-08 15:14

>>136
Joel on /prog/

Name: Anonymous 2011-09-19 6:31

bampu

Name: Anonymous 2011-09-19 7:12

this thread is VIP QUALITY

Name: Anonymous 2011-09-24 17:09

>>3

LuaJIT and Lua/LLVM still using those god damn look-up tables in the JITed code.

The table look up certainly isn't ideal, compared to indexing into an organized location within a struct, but it isn't that bad. Strings in lua are interned into a symbol table, which means that all strings with equal contents are actually the same string, starting at the same memory address. Because of this, using strings as keys in a hash table in lua is as efficient as using pointers as keys. Also, many class-like and struct-like tables in lua don't usually have that many fields, maybe 12 or 15 at the max, unless of course there is a massive amount of inheritance going on. Any more and it wouldn't be easy for a programmer to follow the code. A typical hash table using some type of probing scheme will usually keeps it's array length around twice as much as there are objects in it, yielding structs that are around twice as large as they normally would be. This a cost, but it isn't that bad. Lua is a simple language, and typically out performs other interpreted languages. It's flaws aren't in speed. You can certainly criticize it for not having any support for threads, and having a pretty limited standard library. You can't even do a chdir without extending it with C, and there isn't built in support for real regular expressions, which is a little baffling for me since it is a scripting language and regex is usually their niche.

Name: Anonymous 2011-09-24 17:18

>>144
I'm surprised Lua doesn't have some form of typed defstruct as well.

Name: Anonymous 2011-09-24 17:31

>>145

yeah me too. I'm sure developers using it in games would really appreciate it. It wouldn't require very much deviation from the language either, in fact, it might be implementable as is with some crazy hacks. Because nothing can actually be stored within a struct, just references to other values, a struct with n fields of arbitrary types can be implemented as a lua table using only the indecies, 1 .. n as keys. Doing this would ensure that it would look like a regular array under the hood. Then you could have table mapping field names to positions within the array:


apple_struct_field_locations = {num_seeds = 1,
                                color = 2,
                                age = 3}


and then, somehow have lua locate every point in your code where an apple_struct is being indexed by one of the three constant keys above, and inline replace it:


apple_struct.num_seeds = 2
   ->
apple_struct[apple_struct_file_locations['num_seeds']] = 2
   ->
apple_struct[1] = 2


I can't think of a way to get this, other lisp style macros though.

Name: Anonymous 2011-09-24 18:34

>>145,146
apparently at least some game engines that use lua use a modified vm. for example, havokscript which is basically an optimized lua interpreter with built-in structures: http://www.gdcvault.com/play/1014795/Havok-Script-Efficient-Lua-Scripting (slides 29-31)

however i would imagine luajit (where supported) will probably be the preferred option, especially with its ffi

Name: Anonymous 2011-09-24 19:09

>>147
Nnnnnnope. See http://www.havok.com/index.php?page=havok-script:

Request an evaluation version of Havok Script

They want to make money. Money. And nothing else.

And since it's closedsource, there's a very good chance it's just vanilla Lua with some minor internal changes, like name, file extensions, maybe even changes in the bytecode generator.

But hardly anything that could possibly classify as ``better''.

Name: Anonymous 2011-09-24 19:21

why don't they just get an L3 cache on the XBox? :/

Name: Anonymous 2011-09-24 19:22

I'm guessing poor Lua performance comes from guys who don't understand how lexical closures work and so make hash tables for every persistent bit of data.

Poor perforamnce is caused by cretins who write inelegant bullshit, not languages.

Name: Anonymous 2011-09-24 20:02


                       //`'''```,
             o        // LISP   `.,
       ,....OOo.   .c;.',,,.'``.,,.`
    .'      ____.,'.//
   / _____  \___/.'
  | / ||  \\---\|
  ||  ||   \\  ||
  co  co    co co

Name: Anonymous 2011-09-24 20:32

>>151

indeed

Name: Anonymous 2011-09-24 21:03

>>151
kill yourself.

Name: Anonymous 2011-09-24 21:04

>>150
Lexical closures still require more space per slot than a properly-packed zomg-optimized structure. Just saying, I'm an avid defender of closures but I don't find that they are a proper replacement for structs.

Name: Anonymous 2011-09-24 22:14

>>154
but they don't cause a cache miss every line like self.foo does.

Name: Anonymous 2011-09-24 22:16

>>155
Did you even read my post?

Name: Anonymous 2011-09-24 22:38




function make_value(v)
  return function() return v end,
         function(new_v) v = new_v end
end

function make_struct(...)
  local functions = {}
  for i,v in ipairs({...}) do
    getter, setter = make_value(v)
    table.insert(functions, getter)
    table.insert(functions, setter)
  end
  return unpack(functions)
end

function main()
  local get_name,   set_name,
        get_age,    set_age,
        get_gender, set_gender = make_struct('John', 34, 'male')

  print(get_name())  --> prints John
  print(get_age())   --> prints 34
  set_age(56)
  print(get_age())   --> prints 56
end

main()


>>155

WHOA WHOA WHAT NOW BRO? WHAT NOW?

Name: Anonymous 2011-09-24 22:42

lexical clojures

Name: Anonymous 2011-09-24 23:51

>>157
That's some impressive table-hackery, but please tell me you don't do that in production code.

Name: Anonymous 2011-09-25 0:55

>>159
yeah, who the hell just dumps varargs into a table and iterates it

have fun with your nils

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List