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
Viper2026
Dec 15, 2004
I got iRaped by Steve Jobs and all I got was this custom title.

rjmccall posted:

Proper "lazy" evaluation (as it appears in e.g. Haskell) is a little more subtle than that, but yeah, you get the general idea.
code:
if
is a special form in LISP/Scheme that can't be duplicated by a simple user-defined function, precisely because it only evaluates one of its second and third arguments, and which one depends on the result of the first. I believe it can be duplicated with a macro, though.

Yeah, after doing some more reading this is clear now, thanks :c00l:

Adbot
ADBOT LOVES YOU

defmacro
Sep 27, 2005
cacio e ping pong

Vanadium posted:

Can you implement cond with a macro, without using if or whatever? :colbert:

Here's IF without COND
code:
CL-USER> (defmacro coolif (condition then-branch else-branch)
           `(or (and ,condition ,then-branch)
                ,else-branch))
COOLIF
CL-USER> (coolif (= 0 0) 3 4)
3
CL-USER> (coolif (= 0 0) 4 3)
4
CL-USER> (coolif (= 0 0) 4 (print "rear end"))
4
I removed the note that was printed after the last call. It was removing the unexecutable code after the short circuiting.

There's IF. COND is based (generally) an IF, you could see some sample source here. Here's it defined with my IF:
code:
CL-USER> (defmacro coolcond (&rest clauses)
           (coolif (endp clauses)
                   nil
                   (let ((clause (first clauses)))
                     (when (atom clause)
                       (error "coolcond clause is not a list: ~S" clause))
                     (let ((test (first clause))
                           (forms (rest clause)))
                       (coolif (endp forms)
                               (let ((n-result (gensym)))
                                 `(let ((,n-result ,test))
                                    (coolif ,n-result
                                            ,n-result
                                            (coolcond ,@(rest clauses)))))
                               `(coolif ,test
                                        (progn ,@forms)
                                        (coolcond ,@(rest clauses))))))))
COOLCOND
CL-USER> (macroexpand-1 '(coolcond ((= 0 0) 3) ((= 0 1) 4) (t 2)))
(COOLIF (= 0 0) (PROGN 3) (COOLCOND ((= 0 1) 4) (T 2)))
T
CL-USER> (coolcond ((= 0 0) 3) ((= 0 1) 4) (t 2))
3
CL-USER> (coolcond ((= 0 1) 3) ((= 0 1) 4) (t 2))
2
CL-USER> (coolcond ((= 0 1) 3) ((= 1 1) 4) (t 2))
4
Generally IF is written as a special form and COND is written as a macro using IF, as seen in the above code. You could write COND with just AND/OR/etc. but it'd probably be a pain in the rear end. Obviously, the copy/pasted macro is nicer than mine (gensyms to prevent symbol collisions etc.) but I think you get the idea.

ps: lisp rules :colbert: :coal:

defmacro fucked around with this message at 23:00 on Sep 16, 2008

Vanadium
Jan 8, 2005

GT_Onizuka posted:

ps: lisp rules :colbert: :coal:

Now if only someone would take all the cool features and put them into a useful language. :c00lbert:

defmacro
Sep 27, 2005
cacio e ping pong

Vanadium posted:

Now if only someone would take all the cool features and put them into a useful language. :c00lbert:

that's cool, not enough parentheses though

defmacro fucked around with this message at 18:37 on Sep 16, 2008

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Vanadium posted:

Now if only someone would take all the cool features and put them into a useful language. :c00lbert:

That's pretty much what every language developement in the last 40 years has been (except for the "all").

tef
May 30, 2004

-> some l-system crap ->

Vanadium posted:

Now if only someone would take all the cool features and put them into a useful language. :c00lbert:

Man C++ needs a seperate symbol table for functions and variables.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
I have various data formats that drive a data import system. And some of these formats have one database table worth of information, which is easy to work with. Others have multiple tables. In either case, I want to see one row (one atomic concept) worth of information that is used by the rest of the data import system. So, with one table, each row is a complete entity. With the multiple tables, they need to be joined together (on a key, obviously), and together, they will represent one complete entity (similar to the one table scenario).

My question is, how do I model/design this to handle an N amount of tables? I realize that for joins, you have a base table and then a set of auxilary tables, and each auxilary table has a join condition... How do I program this?

Do I manually make an SQL statement that creates a view, and program this into the data format (implemented by a class)? Or do I somehow make a join condition per auxilary table and associate that with each auxilary table (implemented by metadata in a database)?

Farrok
May 29, 2006

I have extensive experience using MATLAB to write a variety of programs mostly related to image analysis. I have zero experience with anything that's lower-level than that, except a brief introduction to Java when I first learned MATLAB 5 years ago. However, I have begun feeling somewhat limited with only this experience and so I want to learn a more 'proper' language. I actually have a little project in mind that I want to do, and I feel that it would be a good opportunity to expand my horizons a bit. I could write this program very quickly in MATLAB, but aside from wanting to try something new, I also have an eye to eventually running it on Windows Mobile so I can use it on my phone.

Will my experience with MATLAB be helpful as I delve into something new, or will it still feel like starting from scratch? I have a good but not formal understanding of complexity theory and so on from having to write time constrained programs, but at what point is it necessary for me to deepen this understanding with a more formal background (ie from classes or a proper text book or CS reference)? And finally, if I can actually do this and want to use it on my phone, is there anything in particular I should know about programming for Windows Mobile? Any languages that aren't well supported or different considerations I need to always keep in mind, like screen size?

SixPabst
Oct 24, 2006

I'm not sure where the most appropriate place for this question is, but does anyone have a recommendation for a good SMS/Text Message API provider? Have you used any specific company before? This is a smaller project (maybe a couple hundred SMS messages a month) for a client and we're both located in the US, if that matters.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

Farrok posted:

Will my experience with MATLAB be helpful as I delve into something new, or will it still feel like starting from scratch? I have a good but not formal understanding of complexity theory and so on from having to write time constrained programs, but at what point is it necessary for me to deepen this understanding with a more formal background (ie from classes or a proper text book or CS reference)? And finally, if I can actually do this and want to use it on my phone, is there anything in particular I should know about programming for Windows Mobile? Any languages that aren't well supported or different considerations I need to always keep in mind, like screen size?

Knowing any programming language makes learning the next one easier, until you eventually can just pick them up, study the novel parts and get going. (I'm onto my 14th language. After a while, they all look the same ...) And Matlab is a decent structured language that basically Algolic, so you'll be in familiar territory with most modern programming languages. I think you can just leap in and worry about theoretical considerations a little later.

Matlab has a lot of similarity to Python, which I'm a big fan of, but if you're looking to target WinMobile, it might not be the right choice. (There are people doing work with Python on mobile devices - but it's unclear to me if the tools are solid or if it's still at the the hacking stage.) In that case, it may make the most sense to target Windows tools and frameworks, so you're looking at .Net, C# and VB. More experienced people can tell you what the preferred approach is.

Now my question: at my place of work (a scientific laboratory), there are people that spend their time manually classifying fly wings. That is, they receive a strange fly, photograph its wing, blow it up and compare it to a bunch of reference photographs to determine what species and strain the fly is. Apparently, flies have characteristic wing shapes and vascular patterns in their wing.

While observing this, I idlely thought that this should be a relatively simple image analysis and categorisation problem. The photos are good quality, there's no background, and the wings are simple but distinctly different. But it's been years since I did anything with imaging. Any pointers on the sort of tech or algorithms I should be looking at? Even a bunch of buzzwords would give me something to google for.

Farrok
May 29, 2006

outlier posted:

Useful Words
+
While observing this, I idlely thought that this should be a relatively simple image analysis and categorisation problem. The photos are good quality, there's no background, and the wings are simple but distinctly different. But it's been years since I did anything with imaging. Any pointers on the sort of tech or algorithms I should be looking at? Even a bunch of buzzwords would give me something to google for.

Thanks for the info, thats quite helpful! As to your question, if the vein patterns are as regular for a given fly as you say, it should be quite easy to use any of a variety of image similarity measures to classify them. In particular, cross correlation or sum of square differences (especially the latter) are very easy algorithms to implement. The hard part is determining whether your image of interest needs to be translated or rotated in order to compare it to the reference image...that can be done manually, but then you might as well go ahead and classify it manually, too. You can use methods like gradient decent that iteratively approaches the the right orientation based on improvements in the similarity measures.

Be sure if you try different measures that its easy to switch back and forth between looking for minima and looking for maxima, though. Sum of square differences is a perfect match if it is 0 and cross correlation is perfect if it is 1, for example.

Boz0r
Sep 7, 2006
The Rocketship in action.
I want to write a program to access .map files from old Build engine games(specifically Blood), get the architecture information, and extract it as a model file for use in 3ds max.

Only problem is, I have limited programming knowledge, I want to write it in Java as it's the only language I know, I can't find any information as to how the .map files are constructed, and I don't really know where to start.

Does anyone have any suggestions? :D

TSDK
Nov 24, 2003

I got a wooden uploading this one

Boz0r posted:

I want to write a program to access .map files from old Build engine games(specifically Blood), get the architecture information, and extract it as a model file for use in 3ds max.

Only problem is, I have limited programming knowledge, I want to write it in Java as it's the only language I know, I can't find any information as to how the .map files are constructed, and I don't really know where to start.

Does anyone have any suggestions? :D
Check out Ken Silverman's page for the source code and file format information:
http://www.advsys.net/ken/build.htm

For output into a format that art packages can read, you should probably investigate Collada.

Boz0r
Sep 7, 2006
The Rocketship in action.

TSDK posted:

Check out Ken Silverman's page for the source code and file format information:
http://www.advsys.net/ken/build.htm

For output into a format that art packages can read, you should probably investigate Collada.

Thanks, that was actually pretty helpful. I think I'm going with the Wavefront OBJ. file format, as I know it already and it's pretty straightforward.

Now I just have to interpret this code, as I don't know too much C.

EDIT: Does anyone know how to parse an array of bytes as an integer in java?

Boz0r fucked around with this message at 22:56 on Sep 18, 2008

LLJKSiLk
Jul 7, 2005

by Athanatos
C# case/switch

code:
switch (RecType)
{
   "ABC":
      return "DEF";
   "DEF":
      return "GHI";
}
C# if/then/else

code:
if (RecType == "ABC")
{
   return "DEF";
}
else if (RecType == "DEF")
{
   return "GHI";
}
else if (RecType == "GHI")
{
   return "JKL";
}
Question: Besides looking cleaner, what is the speed performance benefit of switch statements versus if/then/else arguments - and at what point does this become noticeable?

What I'm doing is passing a string abbreviation into a subroutine and returning a different abbreviation (migrating systems) based on what it finds. There are 96 possible abbreviations that I'll be passing in, but not quite so many that I'm passing out. For instance there are several 'types' of certain documents that I'm just transferring into an overall type of document.

I have a long as hell subroutine (one case for each of the 96 possibles), but I figured that the switch/case was the way to go. That being said - I'm going to be calling this routine about 3000 times per day.

I didn't use any break; lines because the only processing is the return value, and the compiler warned that the break wouldn't be reachable anyway (I suppose since I'm passing directly to return).

Is there anything else I should look at doing to optimize this portion, or is it pretty much negligible in performance?

TL;DR: I've got a subroutine with a string parameter that returns a string based on one of 96 string cases in a switch statement. Anything I can think of doing to make the code faster?

floWenoL
Oct 23, 2002

SiLk-2k5 posted:

TL;DR: I've got a subroutine with a string parameter that returns a string based on one of 96 string cases in a switch statement. Anything I can think of doing to make the code faster?

Why in god's name are you not using a hashtable.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

SiLk-2k5 posted:


Question: Besides looking cleaner, what is the speed performance benefit of switch statements versus if/then/else arguments - and at what point does this become noticeable?

None whatsoever.

The only difference between switch and if is that switch only evaluates the condition once, and if evaluates it for each "else if" clause. When the condition is a simple variable like this, there's nothing to evaluate so there's no difference at all.

Also, if the condition is a complex expression or a function call that the compiler can determine returns the same result every time and has no side effects, any decent compiler will optimize it out so it only gets evaluated once anyway.

Finally, this is a trivial change to make later, so when you've finished writing and debugging your program and the last problem with it is that it's slow, and you track down the slowness to this particular section of code, then you can start wondering whether changing between if and switch will fix it. (It won't.)

quote:

I have a long as hell subroutine (one case for each of the 96 possibles), but I figured that the switch/case was the way to go. That being said - I'm going to be calling this routine about 3000 times per day.

96 possible values? 3000 times per day? Miniscule. You've now wasted more time thinking about this than you could ever possibly save by optimizing.

floWenoL
Oct 23, 2002

JoeNotCharles posted:

None whatsoever.

The only difference between switch and if is that switch only evaluates the condition once, and if evaluates it for each "else if" clause. When the condition is a simple variable like this, there's nothing to evaluate so there's no difference at all.

Also, if the condition is a complex expression or a function call that the compiler can determine returns the same result every time and has no side effects, any decent compiler will optimize it out so it only gets evaluated once anyway.

This is so off-base it's not even funny. :psyduck:

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

floWenoL posted:

Why in god's name are you not using a hashtable.
Specifically, C#'s Dictionary.

Vanadium
Jan 8, 2005

Just convert the string into a long by ORing together the individual chars, then you can switch on the long and then you get O(1) instead of O(96) wait no

Vanadium
Jan 8, 2005

Just put every output string into a separate file with input string as the name, then your function can just open it and read out the result and you do not have to switch or anything.

Vanadium
Jan 8, 2005

Can you not just use LINQ or something in this case

code:
var query =
  from pair in new string[][] { 
    new string[] {"ABC", "DEF"}, 
    new string[] {"GHI", "JKL"},
    ...
  }
  where pair[0] == key
  select pair[1];
foreach (string result in query) {
  return result;
} 
    
return null;
vvv when in rome...

Vanadium fucked around with this message at 01:33 on Sep 19, 2008

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

Vanadium posted:

Can you not just use LINQ or something in this case
What are you, Victor?

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

floWenoL posted:

This is so off-base it's not even funny. :psyduck:

Really? How does it work then?

floWenoL
Oct 23, 2002

JoeNotCharles posted:

Really? How does it work then?

Switch statements lend themselves to jump tables when the data types are bounded integer values, but this is only in C or C++, and I guess maybe C# sometimes, but of course for strings this can't be done.

I don't know if C# does inter-procedural optimization. Maybe it does. But generally unless its inlined data flow analysis won't optimize it out for ifs.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.
Bah, I didn't even notice we were talking about strings and not ints.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Conceivably, a compiler could compile a string switch into an int switch on a perfect hash, where each case verifies the match. I don't know of any compilers that actually do it, though.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

Farrok posted:

Thanks for the info, thats quite helpful! As to your question, if the vein patterns are as regular for a given fly as you say, it should be quite easy to use any of a variety of image similarity measures to classify them. In particular, cross correlation or sum of square differences (especially the latter) are very easy algorithms to implement. The hard part is determining whether your image of interest needs to be translated or rotated in order to compare it to the reference image...that can be done manually, but then you might as well go ahead and classify it manually, too. You can use methods like gradient decent that iteratively approaches the the right orientation based on improvements in the similarity measures.

Be sure if you try different measures that its easy to switch back and forth between looking for minima and looking for maxima, though. Sum of square differences is a perfect match if it is 0 and cross correlation is perfect if it is 1, for example.

Awesome - thanks. I think I'll try and translate and rotate automatically before doing the manual, but even the manual fitting should be helpful.

LLJKSiLk
Jul 7, 2005

by Athanatos

quote:

Conceivably, a compiler could compile a string switch into an int switch on a perfect hash, where each case verifies the match. I don't know of any compilers that actually do it, though.
Is there any particular reason why I'd want to convert the strings to a numerical value considering that C# handles strings in switch statements just fine? (Using Visual Studio 2005)

quote:

96 possible values? 3000 times per day? Miniscule. You've now wasted more time thinking about this than you could ever possibly save by optimizing.
I've optimized most of the program where I could and had a question about that particular way. Generally it will be 3000 times per day, but the initial batchload will be about a million times or so.

The biggest hangup in the program is built-in WebService calls. The send/response is taking a while, which I'm not sure if it is the server latency (server in Florida) or local code on the server.

In any event, my program is virtually complete aside from waiting on emails to confirm the return strings. Basically this isn't "ABCD" stuff like I put, it is every type of court document that could possibly be filed in a specific county has its own abbreviation in the courthouse, and we have our own abbreviation in our own system. Just trying to figure out the most efficient methods to shave whatever time I can from the web-service lag. I figure it is a minuscule gain regardless, but now was a good time to ask about it for future projects.

Thanks guys.

csammis
Aug 26, 2003

Mental Institution

SiLk-2k5 posted:

Is there any particular reason why I'd want to convert the strings to a numerical value considering that C# handles strings in switch statements just fine? (Using Visual Studio 2005)

Comparing integers is faster than comparing strings.

Boz0r
Sep 7, 2006
The Rocketship in action.
Is there some sort of smart method when I've extracted an array of bytes from a file, to convert them to long, short, or chars in Java?

very
Jan 25, 2005

I err on the side of handsome.
I'm trying to add a dynamic number of items to a Windows CMenu. The only example of doing this in our codebase is this horrible hack:

Every menu item has to have a unique resource ID, so what this person did was to reserve a range of IDs in the resource.h file like this:
code:
#define ID_ASSET_ATTACHTAG              18700
#define ID_ASSET_REMOVETAG              18950
And then define command ranges in the message map:
code:
ON_COMMAND_RANGE(ID_ASSET_ATTACHTAG, ID_ASSET_ATTACHTAG+249, &CGLMaterialTreeItem::OnAssetAttachTag)
ON_COMMAND_RANGE(ID_ASSET_REMOVETAG, ID_ASSET_REMOVETAG+249, &CGLMaterialTreeItem::OnAssetRemoveTag)
We just assume that nobody was going to use any IDs within the range 18700 to 19200. This is retarded because you have to hack the resource.h manually to do this, you can't put it into the .rc file. Also, if there are more than 250 tags, this solution breaks. And lastly, the tags are a hierarchy so we have to go through the mess of finding a unique ID for each tag to build the menu, and then turn around and find a tag from an ID when the user selects a menu item.

This is obviously a lovely solution, and I was pissed when one of our Sr. developers told me that it was the only way to do this.

Surely there must be a way to set up a message map that can take a parameter of some sort, and make a menu item that passes the parameter along? I couldn't find anything that would tell me how to do this, or if it were even possible, but really I don't know what to search for.

csammis
Aug 26, 2003

Mental Institution

Boz0r posted:

Is there some sort of smart method when I've extracted an array of bytes from a file, to convert them to long, short, or chars in Java?

The Java megathread might have something to help you out.

very posted:

Surely there must be a way to set up a message map that can take a parameter of some sort, and make a menu item that passes the parameter along? I couldn't find anything that would tell me how to do this, or if it were even possible, but really I don't know what to search for.

You shouldn't be creating static IDs for dynamic menus. Does this help?

very
Jan 25, 2005

I err on the side of handsome.

csammis posted:

You shouldn't be creating static IDs for dynamic menus. Does this help?
I had accomplished what I was trying to do without dynamic menu items, but I will keep this in mind. Thanks.

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.
What are good papers/books that offer an introduction to financial market analysis algorithms? I'm mostly interested in analyzing historical trends, but I know absolutely nothing about this area of research and will happily read anything pertinent to the field.

The B Man
Mar 21, 2007
'Cause life's too short to play Freebird

Plastic Jesus posted:

What are good papers/books that offer an introduction to financial market analysis algorithms? I'm mostly interested in analyzing historical trends, but I know absolutely nothing about this area of research and will happily read anything pertinent to the field.

Check out Fama 1970 and Fama 91, they're both an overview of market efficiency which will basically tell you that technical analysis (ie some sort of algorithm) has not and will not yield profit. I'm not sure exactly what you're looking for but you can't do any sort of futuristic prediction. If you want to analyse past data you're be better off looking at statistical methods for doing so.

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.

The B Man posted:

Check out Fama 1970 and Fama 91, they're both an overview of market efficiency which will basically tell you that technical analysis (ie some sort of algorithm) has not and will not yield profit. I'm not sure exactly what you're looking for but you can't do any sort of futuristic prediction. If you want to analyse past data you're be better off looking at statistical methods for doing so.

No, I'm not trying to open my own quant shop. I'm mostly looking to learn about software and mechanisms are used by analysts to evaluate markets and trends. I'm also specifically wanting to analyze interactions/dependencies between index fund components, in particular when these dependencies contradict overall market performance.

kruna
Jun 6, 2006
I missed the rapture.
I have a question about C++. First though I wanna provide some of my background so you know where I'm coming from. Basically I studied Java for 2 years in high school, then after that I studied some C++ on my own. I can read C++ very well and I've done some programming, but I haven't actually done any programming in a while. Recently I got hired at my university to help a professor with her physics research. I run and maintain this clunky Fortran (I learned on my own from the ground up) program we use to crunch numbers, Fortran is great for number crunching but I just don't feel comfortable doing some things with it. And well, I think I could save us some time if I could program something on top of Fortran, using C++. So I need someone to point me in the right direction I need to go to learn how to run another program via C++. Just some commands and a tutorial link would be greatly appreciated. I can figure out the rest on my own probably. Thanks in advance goons

csammis
Aug 26, 2003

Mental Institution

kruna posted:

So I need someone to point me in the right direction I need to go to learn how to run another program via C++.

I can't search for it to find you a precise post, but I'm almost positive that this has been covered in the C++ megathread. Launching another program (and waiting for response, or not) is platform-dependent, so if you need to post in that thread, be sure to mention what OS this will be running on.

Adbot
ADBOT LOVES YOU

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Also if your problem is that the Fortran program is clunky, using C++ to call out to it isn't exactly going to resolve that. :geno:

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