|
C-Euro posted:How? My plan is Various pieces of documentation give examples for using it, see Google for details.
|
# ? Sep 15, 2010 21:32 |
|
|
# ? May 17, 2024 00:24 |
|
I'm writing something in SML (functional programming), but I think it's a basic, general problem. The problem is that my guards aren't working; they are parsed, but in the wrong way. I am trying to make a check that ensures that my first argument consists of - only - eight digits. code:
The under and over test work as they should - at least in terms of the exceptions they raise: respectively Under and Over. The seemingly correct parameter, however, raises the Under exceptions, which seems to be the general problem. Ideally, I just want to write if 9999999 < k andalso k < 100000000 then raise Error else <script>, but for the time being, I'm trying to find out what the hell is wrong, and why I've wasted so many hours troubleshooting.
|
# ? Sep 15, 2010 23:48 |
|
Your logic is confused. If you call myfunc with an eight-digit number as the first parameter, it will recursively call itself with that number divided by 10, which only has seven digits, and that recursive call will then raise the Under exception. What do you want to happen?
|
# ? Sep 15, 2010 23:59 |
|
ShoulderDaemon posted:Your logic is confused. If you call myfunc with an eight-digit number as the first parameter, it will recursively call itself with that number divided by 10, which only has seven digits, and that recursive call will then raise the Under exception. What do you want to happen? The guards that throw the exception Error are (1) n <= 0, (2) k not being eight digits. EDIT: Think I've got it figured out now. Appreciate the help at a time where I'm completely wasted because I had to keep crunching, which resulted in stupid oversights like that. Will be back with more if anything else comes up. Still a little iffy about what code:
ufarn fucked around with this message at 00:46 on Sep 16, 2010 |
# ? Sep 16, 2010 00:10 |
|
edit: wrong thread.
|
# ? Sep 17, 2010 07:45 |
|
Here's a strange one: I have a little custom hardware box that has a USB port to accept a keyboard. I travel with a laptop (amongst a bunch of other stuff) and was wondering if it were possible to have the laptop appear as a USB keyboard to this device. Maybe take over one of the USB ports to route key-presses through? I don't use that box very often, and it's not worth adding a keyboard to my already-extensive kit just for that. Mind you, I've not priced those fold-up or rollable keyboards to see how cost-effective they are. But the less gear I need to take, the better, and I already have the laptop. I presume this is possible, but I've really no idea. If such a thing does not already exist, it's possible you could sell it to the makers of the box in question, but I've no idea. They might not give a poo poo.
|
# ? Sep 18, 2010 00:08 |
|
Gromit posted:Here's a strange one: Almost certainly not. The hardware size of USB is different for master and slave devices, and your laptop probably does not have hardware capable of handling the slave role. Some netbooks might.
|
# ? Sep 18, 2010 00:30 |
|
IIRC there was at least one emacs person lingering around here that was using CEDET to help them develop. I installed it and set it up and haven't done a single thing with it. I was hoping to at the least use it to try to help my autocomplete stuff for some GUI work I'm doing with FLTK. If I was given a list of methods for a particular widget, I could probably figure out what I need to call. But as it stands, I have to look up the documentation for the widget I'm using and get the exact name and prototype. I assume there's a command I can use to have it pitch stuff to me. As it stands, all this stuff seems to be loaded w/o doing anything.
|
# ? Sep 18, 2010 04:36 |
|
ShoulderDaemon posted:Almost certainly not. The hardware size of USB is different for master and slave devices, and your laptop probably does not have hardware capable of handling the slave role. I presume you mean "side" there, right? I was hoping that "universal serial bus" would be very universal, and be fully bi-directional and just down to what data is sent. Guess I'll look into little fold-up keyboards or something.
|
# ? Sep 18, 2010 08:38 |
|
Even if he did mean "side" instead of "size", master and slave USB connectors are differently shaped specifically to prevent you from connecting host-to-host or device-to-device..
|
# ? Sep 18, 2010 10:10 |
|
i r gud at typin Yeah, I meant "side". USB was designed to be as cheap as possible, and as a result the processing requirements are very different on the two sides, and most controllers can't handle both. Firewire is symmetrical, for what that's worth.
|
# ? Sep 18, 2010 10:26 |
|
pseudorandom name posted:...master and slave USB connectors are differently shaped specifically to prevent you from connecting host-to-host or device-to-device.. Well yeah, but that's only a cable issue, and it's easy enough to get something with the right plugs on it.
|
# ? Sep 18, 2010 14:20 |
|
I've got a bit of a complicated situation. I have a closed source application(HAPPY.exe, say) that calls a DLL I've written once every second. I'd like to have another application(SAD.exe ) send messages/commands to the DLL. The crappy way that I've got it working right now is communicating through textfiles in the same folder. Yeah, hackish and bad. Is there some way that I can send information to a stack/queue or something in the dll? So I have the source for the DLL and SAD.exe, but not HAPPY.exe. How I've been considering doing it is using a code cave in the DLL or HAPPY.exe, which I can totally pull off, but I'd rather an easier and more acceptable method.
|
# ? Sep 18, 2010 21:56 |
|
ante posted:I've got a bit of a complicated situation. Err, you have some misconceptions about what a DLL is. DLL's and EXE's are just blobs of executable code (you functions, main, etc) and data (e.g. constants). What you are talking is about inter-process communication or IPC. In particular it sounds like you want to facilitate IPC through a DLL. To this all you need to do is put the state data for the DLL in some form of fixed shared location. A file is sort of what you want, but I bet what you are really looking for is a memory mapped file or shared memory (or a message queue depending). As long as you DLL code loads the same memory mapped file or shared memory, every call to DLL will see that state. Just make sure you properly serialize (named mutexs or semaphores) access to the data, otherwise your app will run into race condition and other weird and untraceable behavior. Also worth noting the "lifetime" of the data is important. If you need to have data persistent when the DLL in not in memory (and it unloads its shared memory handles), you may need to force a persistent store against the hard-drive. However if there is at least one process attached to the shared memory, it is less of an issue. Links: For Windows For Linux A cross platform solution litghost fucked around with this message at 00:04 on Sep 19, 2010 |
# ? Sep 18, 2010 23:56 |
|
litghost posted:Err, you have some misconceptions about what a DLL is. I just didn't really know how to phrase exactly what I wanted, but yeah. This looks perfect, thanks.
|
# ? Sep 19, 2010 00:21 |
|
I've written a windows batch: set environment_variable=whatever [program].exe /options If I call it from the command line then the environment variable is set and the program executes. If instead I double-click the .bat file from the Windows (XP or 7) gui then the environment variable isn't set though the program still executes. I'm making this .bat file for people who aren't comfortable with the command line, and so I'd like them to be able to double-click the .bat file from the gui. What gives?
|
# ? Sep 20, 2010 18:59 |
|
I hope this is a good place for this question. I just started working through Structure and Interpretation of Computer Programs, and am on problem 1.11, which reads as the following: quote:Exercise 1.11. A function f is defined by the rule that f(n) = n if n<3 and f(n) = f(n - 1) + 2f(n - 2) + 3f(n - 3) if n> 3. Write a procedure that computes f by means of a recursive process. Write a procedure that computes f by means of an iterative process. This is all to be done in Scheme of course. So after awhile I was beating my head against a wall and went ahead and cheated by looking up the answer: code:
I still didn't get it, so I decided to go ahead and write out the function long-hand using f(5) as an example: code:
The problem is -- I *still* don't understand what the iterative example is doing. The recursive function is obviously very easy to write, it's just a straight English -> Scheme translation. But the iterative example solution has me boggled. I do not understand what's going on. I've spent almost every available free moment to think on it over the past few days and I still don't get it. Can someone take a shot at explaining? edit: Whoops, I tried to spoiler the solution but I guess spoiler and code tags don't play nice. RobotEmpire fucked around with this message at 01:43 on Sep 21, 2010 |
# ? Sep 21, 2010 01:40 |
|
RobotEmpire posted:The problem is -- I *still* don't understand what the iterative example is doing. The recursive function is obviously very easy to write, it's just a straight English -> Scheme translation. But the iterative example solution has me boggled. I do not understand what's going on. I've spent almost every available free moment to think on it over the past few days and I still don't get it. Can someone take a shot at explaining? Evaluate the iterative solution by hand and see what it does?
|
# ? Sep 21, 2010 01:51 |
|
It uses an accumulator in the arguments to carry values into recursive statements: roughly, it translates f(n) = n if n<3 and f(n) = f(n - 1) + 2f(n - 2) + 3f(n - 3) if n>= 3. into code:
each time we recurse we replace the values with the next f(...) in sequence so, after one loop a,b,c become f(3), f(2), f(1), and after two a,b,c become f(4), f(3), f(2) we want to recurse until a=f(n). we do this by using m to represent how many steps to take: for n=2 we can return a, for n=3 we must recurse once, and so on -- which gives us the condition m < 3 to exit. so, when say n=5, we start with m=5 a = f(2), then m=4, a=f(3), m=3,f=f(4),m=2,a=f(5) and it returns a.
|
# ? Sep 21, 2010 02:19 |
|
edit: ^^^ This is helpful. I guess my issue is, how do you go about looking at this problem programmatically and arriving at a solution?shrughes posted:Evaluate the iterative solution by hand and see what it does? Right, sorry, I did that last night: code:
RobotEmpire fucked around with this message at 02:31 on Sep 21, 2010 |
# ? Sep 21, 2010 02:21 |
|
RobotEmpire posted:edit: ^^^ This is helpful. I guess my issue is, how do you go about looking at this problem programmatically and arriving at a solution? This problem is interesting - I taught programming to gifted kids this summer and even the top of the top struggled immensely with this particular one for some reason. Did you implement and understand the iterative Fibonacci sequence solution? It's basically just that.
|
# ? Sep 21, 2010 05:12 |
|
Is there a good crash-course on creating a scripting language for use inside your programs?
|
# ? Sep 22, 2010 19:10 |
|
Lua is a popular choice for adding scripting to a program written in another language.
|
# ? Sep 22, 2010 19:14 |
|
If you are using a .NET language, you can use the language's own compiler to read in a script file written in the same language and compile it to a usable object at run time (example here for C#). The idea is to create some base object called ScriptObject with a few virtual function hooks and then inherit from that base by compiling a file that fills in the virtual functions when your program is running. Otherwise, Lua is popular as rt4 mentioned. I've run into problems with using it across different machines - some lua interface .dll files violate security on Vista/Win7 or cause issues with 32bit vs 64bit systems.
|
# ? Sep 22, 2010 19:45 |
|
I've been thinking about something for say a game, where you can have enemy AI or object behavior defined by a script. How does a script interact with your in-game variables? Do you compile it into bytecode or interpret it? It's like a whole project in itself.
|
# ? Sep 22, 2010 19:55 |
|
In lua, you'd just use the C-lua interface to call your "behavior" functions. You can also register callback functions if you need to call some native functions from a lua function. The easiest way to get into the language is probably to read programming in lua. The standard implementation of the execution engine is a bytecode interpreter, but I think there is some JIT version too.
|
# ? Sep 22, 2010 20:58 |
|
Java 6 has JSR-223, Scripting for the Java Platform. Out of the box, it has support for JavaScript.
|
# ? Sep 23, 2010 04:42 |
|
Haven't seen too much IDL talk in this thread, but maybe someone can answer this question. I should also mention that I'm extremely inexperienced with programming in general, this class I'm taking has been my only exposure to it thus far and I don't have anywhere else to turn to for advice right now. I need to write a function that calculates factorials (without using IDL's factorial function of course). (ie: When I input 5, it has to return the result of 5x4x3x2x1). I know this must involve a FOR loop, but I'm unsure of how to implement it to return a single value as opposed to an array, which is how I'd normally use it. And furthermore I don't know how I'm going to use said loop to multiply each number in the sequence. Can I generate a single dimensional array of those values and somehow multiply them all together with array multiplication? I don't really have any code in particular to post, everything I've done so far is for handling instances of (n = 0) or (n < 0) where n is the value to compute the factorial of. Any advice at all would be very appreciated.
|
# ? Sep 23, 2010 05:52 |
|
thevoiceofdog posted:factorial stuff
|
# ? Sep 23, 2010 14:12 |
|
Ruby question here: I've been banging my head against the wall trying to solve what should be a simple problem. I'm using ruby to try to read a text file containing strings of hex characters (like "0xcafebabe 0x1234 0xabcd") and write this to another file in binary format. I can read the input file and turn each entry into a fixnum (using string.hex), but I can't figure out how to turn a fixnum into a byte array that I could just dump to my output file. Any ideas?
|
# ? Sep 23, 2010 22:20 |
|
.chr a number and it becomes a one-character string!!
|
# ? Sep 23, 2010 23:09 |
|
thevoiceofdog posted:Haven't seen too much IDL talk in this thread, but maybe someone can answer this question. I should also mention that I'm extremely inexperienced with programming in general, this class I'm taking has been my only exposure to it thus far and I don't have anywhere else to turn to for advice right now. You might want to google recursion in IDL or iteration in IDL Not familiar with IDL at all but what I do is use "pseudo-codish" writing to figure out how to approach the problem. Let's say your input is x. For x except 0 or 1 I need to multiply x by (x-1), then multiply that product by (x-2) until (x-n) meets my condition that x-n= 1 at which time I'll return my product to the user.
|
# ? Sep 24, 2010 01:46 |
|
Thanks for the feedback guys. Fortunately I figured it out last night, and it was actually pretty simple: the PRODUCT function (which I was not aware of) will multiply all the elements in an array together and return it as one value--couldn't have a more suitable function. I just needed to use a FOR loop to create an indexed array of the values of !n.
|
# ? Sep 24, 2010 03:25 |
|
SnoPuppy posted:Ruby question here: Take a look at Array#pack.
|
# ? Sep 24, 2010 03:27 |
|
thevoiceofdog posted:Thanks for the feedback guys. Fortunately I figured it out last night, and it was actually pretty simple: the PRODUCT function (which I was not aware of) will multiply all the elements in an array together and return it as one value--couldn't have a more suitable function. I just needed to use a FOR loop to create an indexed array of the values of !n. Why would you create an array and multiply all the elements together? If you're looping from 1 to n, why don't you just do the multiplication, you know, in the loop instead of building up and using an array?
|
# ? Sep 24, 2010 04:18 |
|
Seemed a lot more simple to be honest. I spent a couple of hours trying to do it the way you mentioned and couldn't get the right values. I guess I just don't understand the process of loops well enough, but creating an array with values of 1 to n is like second nature to me since I usually work with image arrays. Also I'm not a very good programmer. Either way the resulting program works and I aced the assignment, so I'm happy.
|
# ? Sep 24, 2010 04:59 |
|
OK odd question time, I graduated with BSCS degree about 6 years ago, and swore I would never do this stuff again... I explored the world and joined the military. I've now finished that part of my life up and so now here I am trying to get a foot in the door to development. I can see myself enjoying it now that I've matured. But now I'm faced with the tasks of not being so a hot a performer in the first place (why I burned out at the end of school) being behind everyone else in terms of keeping up with trend and technologies, and being 6 years rusty. What do you all recommend to get my head back in the game. So far I've been tackling the MIT homework problems from their free websites and once they start being hard I might watch the lectures. I think I never could quite get into the projects and never knew to/how to ask for help back in school so every project was a huge blow to my self esteem and just turned me off to the whole thing. Any websites etc that you think would be beneficial would be welcome also.
|
# ? Sep 24, 2010 08:28 |
|
Kallikrates posted:What do you all recommend to get my head back in the game. Think of or pick a project to do and do it. No shame in starting small and building up confidence to tackle larger projects later. Absolutely no shame in being stuck for project ideas and deciding to reimplement something just to see if you can. Don't stop working on the project until you have something you can show someone at the very least. quote:I think I never could quite get into the projects and never knew to/how to ask for help back in school so every project was a huge blow to my self esteem and just turned me off to the whole thing. Well hopefully you can get into a project you start yourself, otherwise you have some deeper problems. If you're on a project and get stuck, do a quick web search first. Then find the IRC/forum/mailing list hangout of whatever library, language, or type of project you're doing and ask questions. Or come back here. Or find someone who lives near you who knows what's up (e.g. at a local user group). Maybe check in with a former classmate. And if you're really stuck, there's always stackoverflow. If you sort of know what you want to do for a project but are completely at a loss for how to start, come back here with some specific ideas or examples. (A very specific problem and cure: when I was starting out I found refactoring incredibly frustrating because I hadn't heard of version control. I'd have something sort of working, then work on it only to screw it up more, but by then I'd lost what I had before. If going backwards like that sounds familiar, a quick stop by the version control thread is worth your time.) quote:Any websites etc that you think would be beneficial would be welcome also. Pretend you're just getting started again and check out the CoC FAQ, feeling free to skip the incredibly basic stuff you already know. (But be honest; glancing over something and saying "I sort of remember this" isn't the same as actually being able to do it.)
|
# ? Sep 24, 2010 11:13 |
|
thevoiceofdog posted:Seemed a lot more simple to be honest. I spent a couple of hours trying to do it the way you mentioned and couldn't get the right values. I guess I just don't understand the process of loops well enough, but creating an array with values of 1 to n is like second nature to me since I usually work with image arrays. Also I'm not a very good programmer. I think the way I would have done it, assuming n doesn't get too large is something like: code:
|
# ? Sep 24, 2010 12:36 |
|
|
# ? May 17, 2024 00:24 |
|
mr_jim posted:Take a look at Array#pack. I eventually figured out a way to do it, but it feels very clunky. Assuming that "addr" is a Fixnum, this is what I've settled on to get an array where element 0 corresponds to byte 0: code:
|
# ? Sep 24, 2010 17:33 |