Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 708 709 [710] 711 712 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 840320 times)

MoonyTheHuman

  • Bay Watcher
  • I think the DEC VAX hates me.
    • View Profile
    • hellomouse
Re: if self.isCoder(): post() #Programming Thread
« Reply #10635 on: October 24, 2017, 01:57:59 pm »

have tried GPU acceleration. can confirm.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10636 on: October 24, 2017, 08:16:16 pm »

Have done GPU acceleration many times with successes and failures.  Can also confirm.  Can also confirm that OpenCL is like the analogy above, except that depending on which road (computer architecture) you're on, the clown cars might also have flat tires.
Logged
Through pain, I find wisdom.

MoonyTheHuman

  • Bay Watcher
  • I think the DEC VAX hates me.
    • View Profile
    • hellomouse
Re: if self.isCoder(): post() #Programming Thread
« Reply #10637 on: October 31, 2017, 12:20:21 pm »

Im designing a small programming language to be used for game design, and would like some feedback on it. I've put a code snippit in a spoiler with documentation on whats going on.
Note this is a very rough sketch of what the syntax will be, and your feedback will be important.
Spoiler: example for Harmony (click to show/hide)

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10638 on: October 31, 2017, 12:38:31 pm »

I'm not sure what exact problem you're trying to solve there. If you're looking to make a language for e.g. games then you shouldn't redesign the language at such a low level. The point of a game-specific language is to build in support for game designers who aren't hardcore programmers.

Using the word "object" instead of class will just confuse people. The commonly understood semantics is that a "class" (or "type" as in it's a class of things, e.g. a classification) defines what a thing is, and an object is an instance of the class/type of thing. I'd highly recommend not using keywords that don't commonly appear in other languages. It makes it easier to understand, but also easier to port code to your language. It minimizes the difficulty of learning it.

Possibly, if you're making a new language I'd suggest starting with a thing like Python and not curly-braces notation. Curly braces are a source of bugs since they can be misaligned or missing. How much time do people spend checking that their curly braces are lined up properly, and how often does cut/paste coding lead to missing or stray curly braces? Do away with that and use Pythons indentation-based system. It's cleaner, shorter, easier to debug and enforces proper scoping / indents, while also ending the argument about where the opening brace goes.
« Last Edit: October 31, 2017, 01:23:40 pm by Reelya »
Logged

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10639 on: October 31, 2017, 12:58:55 pm »

First, is this supposed to be a scripting language to run on a VM?

If not, STOP, you won't be able to match the performance of a professional language.

If so, here are some tips:
* Object orientation is adding a lot of complexity for minor gain. Lua works the way it does for a very good reason.
* "->" in declarations is unneeded. Your users will not thank you for more stuff to type.
* In the same vein ":" after the name in a declaration (or worse, in a parameter list) can be removed.
* I hope those semicolons are optional. You do not need semicolons. The only time you need a statement terminator is if you have a statement where the end is not obvious, such as a return with multiple values or a break or continue statement with a following label, and there are better ways to solve such edge cases. (Actually, the two examples given are the only two I have ever encountered...)
* I would also like to reiterate the other advice on weird keywords. Don't do that, use common keywords like other languages.
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS

MoonyTheHuman

  • Bay Watcher
  • I think the DEC VAX hates me.
    • View Profile
    • hellomouse
Re: if self.isCoder(): post() #Programming Thread
« Reply #10640 on: October 31, 2017, 01:03:39 pm »

First, is this supposed to be a scripting language to run on a VM?

If not, STOP, you won't be able to match the performance of a professional language.

If so, here are some tips:
* Object orientation is adding a lot of complexity for minor gain. Lua works the way it does for a very good reason.
* "->" in declarations is unneeded. Your users will not thank you for more stuff to type.
* In the same vein ":" after the name in a declaration (or worse, in a parameter list) can be removed.
* I hope those semicolons are optional. You do not need semicolons. The only time you need a statement terminator is if you have a statement where the end is not obvious, such as a return with multiple values or a break or continue statement with a following label, and there are better ways to solve such edge cases. (Actually, the two examples given are the only two I have ever encountered...)
* I would also like to reiterate the other advice on weird keywords. Don't do that, use common keywords like other languages.
It's built to be used in a VM, and potentially, on a actual CPU (via LLVM IR)
But yea, as i said, that was a rough sketch. I'll keep this in mind.

RoguelikeRazuka

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10641 on: November 28, 2017, 02:19:47 pm »

Hey is there a way (some library etc) in C# (or Python) to parse mathematical expressions (namely, functions of n variables given as a string) and return delegates (or lambdas) that you can call repeatedly at run time?

Say, we have a math expression like "2*x1+sin(x2)+exp(3.557*x3)" written in a file (or read as input from keyboard etc). Now I want to read the expression from that file, store it in a string variable, and then get a function that will calculate this expression when given three arguments for x1, x2, x3.

Is there a way I can do this in C# (or Python) not implementing such tool myself?
« Last Edit: November 28, 2017, 02:32:30 pm by RoguelikeRazuka »
Logged

bloop_bleep

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10642 on: November 28, 2017, 02:36:55 pm »

Check out SymPy. I'm on mobile and am about to board a plane, so I can't say more, but it had what you need.
Logged
Quote from: KittyTac
The closest thing Bay12 has to a flamewar is an argument over philosophy that slowly transitioned to an argument about quantum mechanics.
Quote from: thefriendlyhacker
The trick is to only make predictions semi-seriously.  That way, I don't have a 98% failure rate. I have a 98% sarcasm rate.

monkey

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10643 on: November 28, 2017, 02:37:21 pm »

Logged

scrdest

  • Bay Watcher
  • Girlcat?/o_ o
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10644 on: November 28, 2017, 02:54:05 pm »

It's called an eval
It's a little misleading as advice, since 'eval' also happens to be the name of the Python builtin that implements an eval - but which would fail for this expression.

The eval builtin literally just executes raw Python code provided as string, so it is limited to whatever's in the namespace it has access to at runtime. You'd have to define/import all the possible mathematical operations you're gonna employ.

I haven't used it myself, but as bloop_bleep said, SymPy seems to be the stuff you're looking for.
Logged
We are doomed. It's just that whatever is going to kill us all just happens to be, from a scientific standpoint, pretty frickin' awesome.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10645 on: November 28, 2017, 11:37:24 pm »

JavaScript and Lua both have eval as well.

scrdest is right, however a raw eval will have access to all "basic" math operations, but not necessarily sin, cos, exp etc. So you'd need to test what range of expressions you're allowing and add to that as needed. It might require sticking some preset string of includes at the start of the string you send to eval.

Also, for variables, you'd need to let the eval know what the values of those variables actually are. Here's a rough guide (I only use eval in Javascript so YMMV):

if you eval "1+2" it will return "3", the value of that statement. However if you try and eval "x1+x2" you'll get an error, since eval doesn't know what x1 and x2 mean. Eval is running in it's own scope, so it only knows local variables.

So you'd need to either search and replace the variables (using a builtin string replace function for simplicity) with the real values, or declare them as variables inside the eval right before the statement. e.g. javascript would look like this then:

"var x1 = 1; var x2 = 2; return x1 + x2;" where "x1 + x2" was your original external equation. I'm assuming it's safer to put the "return" keyword here to unambiguously tell the system that you want the whole thing to return the value of "x1 + x2" since there are multiple statements now, and I don't know if it always returns the value of the final one.
« Last Edit: November 28, 2017, 11:41:28 pm by Reelya »
Logged

RoguelikeRazuka

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10646 on: November 29, 2017, 05:54:47 am »

Thank you all for helping me.

If anyone is curious, I solved this in C# following this giude to create a callable-from-C# function of n variables analytical expression for which is given as string:

https://pastebin.com/RJLg7uTf


An additional requirement for my solution to work is that a list of variables used in the expression must be passed, which is not very smart I suppose. Maybe I will find a way to avoid this.


PS I also was able to get a similar result with the help of the sympify, symbols, lambdify functions from SymPy (in Python): https://pastebin.com/VeVZLn3b
« Last Edit: November 29, 2017, 06:15:46 am by RoguelikeRazuka »
Logged

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10647 on: November 29, 2017, 06:02:12 am »

I will say if you're going to parse code from users directly, be sure to strip away anything that isn't a mathematical equation (or return an error).  You never know what people might try to enter into your program.  Both in terms of dumb inputs and malicious inputs.
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule

RoguelikeRazuka

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10648 on: November 29, 2017, 06:48:55 am »

Now, could you suggest me a free plotting library for C# similar to matplotlib? I need a tool capable of drawing graphs of one and two variable functions (so that I could pan the graph, zoom it in and out etc) and present them on a panel/widget embedded in a GUI window. It must be possible to run my app (using this tool) on a pc without additional software (libraries etc) installed and having no internet connection.


Solutions I have found after searching for some on the web:

gnuplot -- great but not embed-able (at least to my knowledge)

ILNumerics -- great but not free

OxyPlot, Live Chars -- great but can't do 3d surface plotting.



More suggestions?
« Last Edit: November 29, 2017, 07:17:22 am by RoguelikeRazuka »
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #10649 on: December 04, 2017, 06:00:30 pm »

A few days have passed, so you may have already found something, but you may have better luck by taking a library from F# space than C# for mathematica/data science type stuff.  I know it's all CLR under the hook so theoretically any F# library should be callable via C#, but how nice that works out, well YMMV...

The first couple I find when I specifically go for F#:
FSharp.Charting
XPlot

I mean, if you've got the taste for it you might be best off just going for F# directly. It's certainly a good fit for mathematical type stuff. Go down the functional rabbit hole! Come join us. Forever and ever and ever... Or at the very least write the core code in F# and expose bindings to the C# (not too tricky with .NET nowadays, since again: It's all CLR under the hood).
« Last Edit: December 04, 2017, 06:16:33 pm by MorleyDev »
Logged
Pages: 1 ... 708 709 [710] 711 712 ... 796