Re: CT regex in AA at compile time
On Tuesday, 7 January 2020 at 15:51:21 UTC, MoonlightSentinel wrote: On Tuesday, 7 January 2020 at 15:40:58 UTC, Taylor Hillegeist wrote: but I can't get it to work. it says its an Error: non-constant expression. I imagine this has to do with the ctRegex template or something. maybe there is a better way? Does anyone know? This issue is unrelated to ctRegex, AA literals are non-constant expressions (probably due to their implementation). You can work around this by using module constructors or lazy initialisation inside of a function: static Regex!char[TokenType] Regexes; shared static this() { Regexes = [ TokenType.Plus: ctRegex!(`^ *\+`), TokenType.Minus: ctRegex!(`^ *\-`), TokenType.LPer: ctRegex!(`^ *\(`), TokenType.RPer: ctRegex!(`^ *\)`), TokenType.Number: ctRegex!(`^ *[0-9]+(.[0-9]+)?`) ]; } Thank you for bringing this to my attention. also, the solution you used is very cool. I had no idea you could put shared static this() just anywhere and have it execute just like it was in main! Does this work for dlls as well?
CT regex in AA at compile time
I'm trying to trick the following code snippet into compilation. enum TokenType{ //Terminal Plus, Minus, LPer, RPer, Number, } static auto Regexes =[ TokenType.Plus: ctRegex!(`^ *\+`), TokenType.Minus: ctRegex!(`^ *\-`), TokenType.LPer: ctRegex!(`^ *\(`), TokenType.RPer: ctRegex!(`^ *\)`), TokenType.Number: ctRegex!(`^ *[0-9]+(.[0-9]+)?`) ]; but I can't get it to work. it says its an Error: non-constant expression. I imagine this has to do with the ctRegex template or something. maybe there is a better way? Does anyone know?
Re: d programs conversion to c
On Saturday, 14 December 2019 at 06:14:23 UTC, BoraxMan wrote: On Wednesday, 11 December 2019 at 18:54:49 UTC, jicman wrote: Greetings! I am trying to see if there are any converters out there from d code to c. Anyone knows? Thanks. josé I don't think there would be any. The BetterC subset is as good as using C. Why specifically do you want to convert? If you want something that works but would be a possible pain. you could always compile the program in d and then use a decompiler, most of these produce C code. It could be a mess though.
Re: optional process
On Friday, 6 December 2019 at 05:09:58 UTC, Paul Backus wrote: On Thursday, 5 December 2019 at 17:27:45 UTC, Taylor Hillegeist wrote: I agree with this. I wasn't clear enough in my question though. I was trying to distinguish between std.functional.compose and std.functional.pipe they look very the same. Pipe says it reverses functions order. Which makes no sense to me. input.pipe!(f, g, h) == input.f.g.h == h(g(f(input))) input.compose!(f, g, h) == input.h.g.f == f(g(h(input))) This is surprisingly clear. I guess I never thought to put multiple functions into pipe that way. It also makes sense why pipe would be the default choice. Thank you, Paul, for the great answer.
Split but keep one delimiter
Learning all the ins and outs of the std library is fun. But there are soo many hidden gems that its hard to tell when to keep looking and when to just write something. I was working on a split function with some particulars: Split but keep exactly one delimiter at the beginning of each section so if splitting on B: BADSFDER ==> BADSF BDER URPBURGER ==> BURP BURGER BBBABBLEB ==> BA BLE B Below is my attempt (As far as I know it works) '''D import std; auto splitB(T)(T irange, T isplitter) if (isInputRange!T){ struct SplitB(T) { private T _str; private T _splitter; private size_t cnt; this(T instr,T splitter){ _str=instr; _splitter=splitter; } bool empty() const{ return _str.length==0; } ref auto front(){ auto tmp = _str.until!"a!=b"(_splitter); auto tmp2 = _str.drop(tmp.count).until(_splitter,Yes.openRight); cnt = tmp.count + tmp2.count; return chain(tmp.takeOne,tmp2); } void popFront(){ _str = _str.drop(cnt); } } return SplitB!T( irange,isplitter); } void main() { "BBAAABSDFSDFBBBAFFA".splitB("A").writeln; } ''' I guess there are two reasons for this post. 1. There are probably much easier ways to do this, I would like to hear about that. 2. This is one of my first complete range setups. Any coding tips / critical comments would be helpful.
Re: optional process
On Thursday, 5 December 2019 at 15:43:30 UTC, Paul Backus wrote: On Thursday, 5 December 2019 at 15:30:52 UTC, Taylor Hillegeist wrote: On Friday, 29 November 2019 at 15:24:31 UTC, Paul Backus wrote: .pipe!((output) { if (sortOutput) return output.sort!("a < b"); else return output; }) .writeln(); // maybe you meant each!writeln ? range .someFunction .each!writeln; So why use pipe? Because in this case, the function we want to apply is a lambda, and you can't call lambdas with UFCS. I agree with this. I wasn't clear enough in my question though. I was trying to distinguish between std.functional.compose and std.functional.pipe they look very the same. Pipe says it reverses functions order. Which makes no sense to me.
Re: optional process
On Friday, 29 November 2019 at 15:24:31 UTC, Paul Backus wrote: .pipe!((output) { if (sortOutput) return output.sort!("a < b"); else return output; }) .writeln(); // maybe you meant each!writeln ? Why pipe as apposed to compose? Pipes functions in sequence. It offers the same functionality as compose, but with functions specified in reverse order. This may lead to more readable code in some situation because the order of execution is the same as lexical order. How does this not reverse the range?
Re: Does D have a tool like pySnooper?
On Friday, 26 April 2019 at 10:22:49 UTC, Bastiaan Veelo wrote: On Friday, 26 April 2019 at 08:35:57 UTC, Bastiaan Veelo wrote: On Thursday, 25 April 2019 at 08:44:14 UTC, Dennis wrote: On Monday, 22 April 2019 at 16:24:53 UTC, Taylor Hillegeist wrote: Or would this not be easy at all with D? I don't think so. While there are lots of traits for introspection of declarations, there is no way to introspect lines of code. The whole function would need to be wrapped into a mixin, and the D code would need to be parsed at compile time for this to work. Yes, but I think that might be doable. You wouldn't need a full blown D parser, just one that can identify statements (`;` being an important clue). Not sure whether __LINE__ will be meaningful inside a mixin, though, but that might also be fixable. It would be an interesting challenge. Bastiaan. Proofing the concept: --- mixin(snoop(q{ int fun(int a, int b) { int c = 3; foreach (i; 1 .. 5) { a += i; } int d = a + b + c; return d; } })); --- Output: 2019-Apr-26 10:33:46.0935135 executed line 7: int c = 3; 2019-Apr-26 10:33:46.0936716 executed line 10: a += i; 2019-Apr-26 10:33:46.0937348 executed line 10: a += i; 2019-Apr-26 10:33:46.0937963 executed line 10: a += i; 2019-Apr-26 10:33:46.0938583 executed line 10: a += i; 2019-Apr-26 10:33:46.0939622 executed line 12: int d = a + b + c; https://run.dlang.io/is/Go97hQ Bastiaan. Hey, that's a pretty cool demo. I saw the idea and wondered rather it could be possible with D. I has some very cool introspection properties. The Link seems to be broken right now. But I think this might be worth some development. Tools like this can really help new users, especially when they are doing things the o'l fashion way, printf for debugging. I doubt it would be too much help for things like ranges, but one must pick their battles. Thanks.
Does D have a tool like pySnooper?
Saw this tool and thought D could probably do something like this pretty easily. Is there such a tool out there already? https://github.com/cool-RR/pysnooper Or would this not be easy at all with D?
Regex replace followed by number.
So I have ran into an issue where I want to replace a string with regex. but i cant figure out how to replace items followed by a number. i use "$1001" to do paste first match but this thinks I'm trying using match 1001 but if i try ${1}001 it gives me an error saying that it cant match the other "}" perhaps D uses a different syntax but i couldn't find any documentation on the replace side. The following code renames files. arg 1 - path arg 2 - regex match arg 3 - regex replace -- import std.file; import std.path; import std.regex; import std.range; import std.stdio:writeln; void main(string[] args){ bool preview; Regex!char myreg; string replacment; if(!args[1].buildNormalizedPath.isValidPath){writeln("Path is invalid! "); return;} try{myreg = regex(args[2]);} catch(RegexException e) {writeln("Invalid Regex command");return;} try{replacment = args[3];} catch(Exception e) {writeln("Needs replacment string");return;} if(args.length < 5){ preview = true; writeln("result is preview only add extra arg for action"); }else{preview = false;} size_t longest=0; foreach (string name; dirEntries(buildNormalizedPath(args[1].driveName(),args[1].stripDrive()) , SpanMode.shallow)) { if(name.isFile){ longest = (longest>name.baseName.length) ? longest : name.length; } } foreach (string name; dirEntries(buildNormalizedPath(args[1].driveName(),args[1].stripDrive()) , SpanMode.shallow)) { if(name.isFile){ if(preview){ writeln("From:",name.baseName," ".repeat(longest-name.baseName.length).join,"to:",replaceAll(name.baseName, myreg,replacment )); }else{ std.file.rename(name,replaceAll(name, myreg,replacment )); } } } } -
Direntries seems to on other drives. (windows)
SO i have a maximum scope depth tool, that i just put together it is super simple. but when i use it in a drive other that C:\ i get an error. Even though i just checked for a valid path. Any ideas? C:\Users\taylor.hillegeist\Documents\CodeSync\D projects\Toys\TOOLS>NestCheck.exe G:\MPLAB\Projects\201001.X\source\ std.file.FileException@std\file.d(3368): G:\MPLAB\Projects\201001.X\source: The system cannot find the path specified. 0x004101B6 in @safe bool std.file.cenforce!(bool).cenforce(bool, lazy const(char)[], immutable(char)[], uint) 0x0043E1C5 in ref std.file.DirIteratorImpl std.file.DirIteratorImpl.__ctor!(immutable(char)[]).__ctor(immutable(char)[], std.file.SpanMode, bool) 0x0042417F in nothrow @nogc rt.util.container.treap.Treap!(gc.gc.Range).Treap.Node* rt.util.container.treap.Treap!(gc.gc.Range).Treap.insert(rt.util.container.treap.Treap!(gc.gc.Range).Treap.Node*, gc.gc.Range) ... import std.file; import std.path; import std.stdio:writeln; void main(string[] args){ int depth=0; int Maxdepth=0; if(!args[1].buildNormalizedPath.isValidPath){writeln("Path is invalid! "); return;} foreach (string name; dirEntries(args[1].buildNormalizedPath , SpanMode.breadth)) { int line =1; int column = 1; depth = 0; if(name.isFile){ writeln(name); string myfile = cast(string) std.file.read(name); foreach(char C; myfile){ if(C == '{' ){ depth+=1; }else if (C == '}'){ depth-=1; }else if (C == '\n'){ line ++; column=1; } if (depth>Maxdepth){ Maxdepth = depth; writeln("In File: ",name," Has a nested depth of: ",depth, " at line: ", line, " column: ", column); } column++; } } } }
Re: byChunk odd behavior?
On Tuesday, 22 March 2016 at 07:17:41 UTC, Hanh wrote: Hi all, I'm trying to process a rather large file as an InputRange and run into something strange with byChunk / take. void test() { auto file = new File("test.txt"); auto input = file.byChunk(2).joiner; input.take(3).array; foreach (char c; input) { writeln(c); } } Let's say test.txt contains "123456". The output will be 3 4 5 6 The "take" consumed one chunk from the file, but if I increase the chunk size to 4, then it won't. It looks like if "take" spans two chunks, it affects the input range otherwise it doesn't. Actually, what is the easiest way to read a large file as a stream? My file contains a bunch of serialized messages of variable length. Thanks, --h I dont know if this helps, but it looks like since take three doesn't consume the chunk it is not removed from the range. import std.stdio; import std.algorithm; import std.range; void main() { auto file = stdin; auto input = file.byChunk(2).joiner; foreach (char c; input.take(3).array) { writeln(c); } foreach (char c; input) { writeln(c); } } Produces: 1 2 3 < Got data but didn't eat the chunk. 3 4 5 6
What is the best minimal runtime for d?
I've been playing around with d with a KL25Z eval board. However it is not easy, It's not easy to know what features are and are not usable. when will i get a linker error to some __eabi_something_not_in_the_runtime. So, question is, does there exist a minimal runtime that will work with LDC/GDC and is up to date? Also I find it interesting that its hard to distinguish what features are language features and which are run-time features. If that is even on someones radar. Also bonus question: How do you think should registers be read and written to in D?
Re: How to import for mixin contents only.
On Thursday, 10 March 2016 at 22:07:23 UTC, Andrea Fontana wrote: On Thursday, 10 March 2016 at 17:43:08 UTC, Taylor Hillegeist wrote: I suppose the linker optimized the functions away since they are now in their own section. But it seems a hacky way to do this. AFAIK assert(0) and other falsey assert have a special meaning for compiler. So probably it's not so hacky but just a way to say that case can't happen. It is used also for: auto myfunc(int i) { if (i == 0) return 10; else if (i == 1) return 3; assert(0); } And also with non final switch using switch(var) { case ... ... default: assert(0); } I'm good with the assert(0), I'm not so happy with the linker not being able to create a binary without the -ffunction-sections option. I think there needs to be a ctimport keyword or something. I should not have to deal with the imports only used during compile time. it is not a good thing.
Re: How to import for mixin contents only.
On Thursday, 10 March 2016 at 17:24:51 UTC, Taylor Hillegeist wrote: On Thursday, 10 March 2016 at 17:22:58 UTC, Taylor Hillegeist wrote: On Thursday, 10 March 2016 at 17:05:26 UTC, Taylor Hillegeist wrote: On Thursday, 10 March 2016 at 16:51:32 UTC, Andrea Fontana wrote: On Thursday, 10 March 2016 at 16:20:42 UTC, Taylor Hillegeist wrote: [...] I wonder if compiler is smart enaugh to undestand that dependency is not needed at runtime in this case: http://dpaste.dzfl.pl/fd3bc2a839a3 well the latest gdc isnt smart enough. So interestingly this will work if i add -ffunction-sections to my compiler options? no idea why? However my binary goes from 4kb with static text to 11kb with the above change. I suppose the linker optimized the functions away since they are now in their own section. But it seems a hacky way to do this.
Re: How to import for mixin contents only.
On Thursday, 10 March 2016 at 17:22:58 UTC, Taylor Hillegeist wrote: On Thursday, 10 March 2016 at 17:05:26 UTC, Taylor Hillegeist wrote: On Thursday, 10 March 2016 at 16:51:32 UTC, Andrea Fontana wrote: On Thursday, 10 March 2016 at 16:20:42 UTC, Taylor Hillegeist wrote: [...] I wonder if compiler is smart enaugh to undestand that dependency is not needed at runtime in this case: http://dpaste.dzfl.pl/fd3bc2a839a3 well the latest gdc isnt smart enough. So interestingly this will work if i add -ffunction-sections to my compiler options? no idea why? However my binary goes from 4kb with static text to 11kb with the above change.
Re: How to import for mixin contents only.
On Thursday, 10 March 2016 at 17:05:26 UTC, Taylor Hillegeist wrote: On Thursday, 10 March 2016 at 16:51:32 UTC, Andrea Fontana wrote: On Thursday, 10 March 2016 at 16:20:42 UTC, Taylor Hillegeist wrote: [...] I wonder if compiler is smart enaugh to undestand that dependency is not needed at runtime in this case: http://dpaste.dzfl.pl/fd3bc2a839a3 well the latest gdc isnt smart enough. So interestingly this will work if i add -ffunction-sections to my compiler options? no idea why?
Re: How to import for mixin contents only.
On Thursday, 10 March 2016 at 16:51:32 UTC, Andrea Fontana wrote: On Thursday, 10 March 2016 at 16:20:42 UTC, Taylor Hillegeist wrote: I feel like this should do what i want it too. but it doesn't. struct Color_t { static if(1==1){ import std.bitmanip:bitfields; immutable string item = bitfields!( uint, "R",8, uint, "G", 8, uint, "B",8, uint, "A", 8); } mixin(item); } I wonder if compiler is smart enaugh to undestand that dependency is not needed at runtime in this case: http://dpaste.dzfl.pl/fd3bc2a839a3 well the latest gdc isnt smart enough. immutable(string) BF(){ if(!__ctfe) assert(0); import std.bitmanip:bitfields; return bitfields!( uint, "R", 8, uint, "G", 8, uint, "B", 8, uint, "A", 8); } struct Color_t { mixin(BF()); } is a fair try as well. but neither work.
Re: How to import for mixin contents only.
On Thursday, 10 March 2016 at 04:56:52 UTC, Mike Parker wrote: On Thursday, 10 March 2016 at 04:07:54 UTC, Taylor Hillegeist wrote: So i want bitfields for just a little bit. but i dont want its dependencies. How is it done. I have tried this. but it doesnt seem to work on gdc. :( struct Color_t { static if(__ctfe){ import std.bitmanip:bitfields; } mixin(bitfields!( uint, "R",8, uint, "G", 8, uint, "B",8, uint, "A", 8)); } __ctfe is a runtime construct, not compile-time. It cannot be used with static if. More over, it's only available *inside* a function that is currently being executed in a compile-time context. It has no role outside of that. What problem are you trying to solve here? I mean, what is the problem with whatever dependencies std.bitmanip:bitfields has that makes you only want to import it during compilation? I feel like this should do what i want it too. but it doesn't. struct Color_t { static if(1==1){ import std.bitmanip:bitfields; immutable string item = bitfields!( uint, "R",8, uint, "G", 8, uint, "B",8, uint, "A", 8); } mixin(item); }
Re: How to import for mixin contents only.
On Thursday, 10 March 2016 at 04:56:52 UTC, Mike Parker wrote: On Thursday, 10 March 2016 at 04:07:54 UTC, Taylor Hillegeist wrote: So i want bitfields for just a little bit. but i dont want its dependencies. How is it done. I have tried this. but it doesnt seem to work on gdc. :( struct Color_t { static if(__ctfe){ import std.bitmanip:bitfields; } mixin(bitfields!( uint, "R",8, uint, "G", 8, uint, "B",8, uint, "A", 8)); } __ctfe is a runtime construct, not compile-time. It cannot be used with static if. More over, it's only available *inside* a function that is currently being executed in a compile-time context. It has no role outside of that. What problem are you trying to solve here? I mean, what is the problem with whatever dependencies std.bitmanip:bitfields has that makes you only want to import it during compilation? I am running on a MKL25Z development board. The output of the mixin works fine. but the dependencies of the std.bitmanip:bitfields are quite extensive. including std.format..etc
How to import for mixin contents only.
So i want bitfields for just a little bit. but i dont want its dependencies. How is it done. I have tried this. but it doesnt seem to work on gdc. :( struct Color_t { static if(__ctfe){ import std.bitmanip:bitfields; } mixin(bitfields!( uint, "R",8, uint, "G", 8, uint, "B",8, uint, "A", 8)); }
Re: An unexpected string to int exception.
On Wednesday, 17 February 2016 at 16:13:47 UTC, Taylor Hillegeist wrote: On Wednesday, 17 February 2016 at 16:11:44 UTC, Taylor Hillegeist wrote: I think the following error message says it all. std.conv.ConvException@C:\D\dmd2\windows\bin\..\..\src\phobos\std\conv.d(2002): Unexpected '1' when converting from type string to type int I would expect that 1 would be among the group of expected items. Also how rude of me: DMD32 D Compiler v2.070.0 code segment in question + if(l.style.canFind("Heading")){ string tmp = l.style[6..$]; ON.incrementNum( to!int(tmp)); + So my error here was i was slicing too early. string tmp = l.style[6..$]; should have been: string tmp = l.style[7..$]; apparently std.conv parse() will say the unexpected input is not the one that caused the error but the character after. in this case "g1" only the 1 was reported.
Re: An unexpected string to int exception.
On Wednesday, 17 February 2016 at 16:11:44 UTC, Taylor Hillegeist wrote: I think the following error message says it all. std.conv.ConvException@C:\D\dmd2\windows\bin\..\..\src\phobos\std\conv.d(2002): Unexpected '1' when converting from type string to type int I would expect that 1 would be among the group of expected items. Also how rude of me: DMD32 D Compiler v2.070.0 code segment in question + if(l.style.canFind("Heading")){ string tmp = l.style[6..$]; ON.incrementNum( to!int(tmp)); +
An unexpected string to int exception.
I think the following error message says it all. std.conv.ConvException@C:\D\dmd2\windows\bin\..\..\src\phobos\std\conv.d(2002): Unexpected '1' when converting from type string to type int I would expect that 1 would be among the group of expected items.
How to force evaluation of range?
So I have this code and I have to add the element .each!(a => a.each!("a")); to the end in order for it to evaluate the range completely and act like I expect it too. Is there a better thing to put in the place of .each!(a => a.each!("a"));? import std.stdio; import std.path; import std.file; import std.uni; import std.range; import std.conv; import std.algorithm; void main(string[] Args){ assert(Args.length>1,"Need a path to source files"); assert(Args[1].isValidPath,"Path given is not Valid!"); dirEntries(Args[1], SpanMode.depth) .filter!(f => f.name.endsWith(".c",".h")) .tee!(a => writeln("\n",a,"\n\t","=".repeat(80).join)) .map!(a => a .File("r") .byLine .enumerate .filter!( l => l.value.byGrapheme.walkLength > 80) .tee!(a => writeln("Line: ",a.index,"\t",a.value)) ).each!(a => a.each!("a")); //Force evaluation of every item }
Re: Can D interface with Free Pascal?
On Saturday, 30 January 2016 at 04:49:39 UTC, Taylor Hillegeist wrote: On Saturday, 30 January 2016 at 04:35:29 UTC, Taylor Hillegeist wrote: On Saturday, 30 January 2016 at 04:11:07 UTC, Mike Parker wrote: [...] Now I'm wishing that was the problem. Interestingly enough when i link to a C shared library it works... but also it isn't show in the needed shared library sections like below. [...] Acctually I made multiple mistakes. 0x000f (RPATH) Library rpath:[--export-dynamic] should be [lib] Ill fix that and test again. dmd Gethello.d -Llibhello.so -L"-rpath=./" made it use the CWD able to load libraries! cool!
Re: Can D interface with Free Pascal?
On Saturday, 30 January 2016 at 04:35:29 UTC, Taylor Hillegeist wrote: On Saturday, 30 January 2016 at 04:11:07 UTC, Mike Parker wrote: [...] Now I'm wishing that was the problem. Interestingly enough when i link to a C shared library it works... but also it isn't show in the needed shared library sections like below. [...] Acctually I made multiple mistakes. 0x000f (RPATH) Library rpath:[--export-dynamic] should be [lib] Ill fix that and test again.
Re: Can D interface with Free Pascal?
On Saturday, 30 January 2016 at 04:11:07 UTC, Mike Parker wrote: On Saturday, 30 January 2016 at 03:43:59 UTC, Taylor Hillegeist wrote: Working through a simple example. I tried the cdecl option but for some reason i can compile but when i run my Gethello it cant find the shared library in the same folder? taylor@taylor-NE510:~/Projects/PASCAL$ nm libhello.so 3ac0 T SubStr taylor@taylor-NE510:~/Projects/PASCAL$ ./Gethello ./Gethello: error while loading shared libraries: libhello.so: cannot open shared object file: No such file or directory The binary's directory is not on the system search path by default on Linux. This page [1] shows three possible solutions. [1] http://www.aimlesslygoingforward.com/2014/01/19/bundling-shared-libraries-on-linux/ Now I'm wishing that was the problem. Interestingly enough when i link to a C shared library it works... but also it isn't show in the needed shared library sections like below. taylor@taylor-NE510:~/Projects/PASCAL$ readelf -d Gethello Dynamic section at offset 0x26dd8 contains 29 entries: TagType Name/Value 0x0001 (NEEDED) Shared library: [libhello.so] 0x0001 (NEEDED) Shared library: [libpthread.so.0] 0x0001 (NEEDED) Shared library: [librt.so.1] 0x0001 (NEEDED) Shared library: [libc.so.6] 0x0001 (NEEDED) Shared library: [ld-linux-x86-64.so.2] 0x000f (RPATH) Library rpath: [--export-dynamic] 0x000c (INIT) 0x4017f8 0x000d (FINI) 0x42 0x0019 (INIT_ARRAY) 0x626db0 0x001b (INIT_ARRAYSZ) 16 (bytes) 0x001a (FINI_ARRAY) 0x626dc0 0x001c (FINI_ARRAYSZ) 16 (bytes) 0x6ef5 (GNU_HASH) 0x4002d0 0x0005 (STRTAB) 0x400aa8 0x0006 (SYMTAB) 0x4002f8 0x000a (STRSZ) 1202 (bytes) 0x000b (SYMENT) 24 (bytes) 0x0015 (DEBUG) 0x0 0x0003 (PLTGOT) 0x627000 0x0002 (PLTRELSZ) 1824 (bytes) 0x0014 (PLTREL) RELA 0x0017 (JMPREL) 0x4010d8 0x0007 (RELA) 0x401090 0x0008 (RELASZ) 72 (bytes) 0x0009 (RELAENT)24 (bytes) 0x6ffe (VERNEED)0x401000 0x6fff (VERNEEDNUM) 4 0x6ff0 (VERSYM) 0x400f5a 0x (NULL) 0x0 taylor@taylor-NE510:~/Projects/PASCAL$ ./Gethello ./Gethello: error while loading shared libraries: libhello.so: cannot open shared object file: No such file or directory
Re: Can D interface with Free Pascal?
On Friday, 29 January 2016 at 01:47:11 UTC, Mike Parker wrote: On Thursday, 28 January 2016 at 19:49:22 UTC, Taylor Hillegeist wrote: On Thursday, 28 January 2016 at 19:33:22 UTC, bearophile wrote: FreeSlave: On Thursday, 28 January 2016 at 08:15:38 UTC, FreeSlave wrote: Not directly. You can declare cdecl function on Free Pascal side and call it as extern(C). What about extern(Pascal)? https://dlang.org/spec/attribute.html#linkage Bye, bearophile Cool!, I did find this little gem. but still havent gotten a hello world to work. I need to figure out which libraries i need to include for fpc dependencies. AFAIK, FreePascal does not use the pascal calling convention by default. If this page [1] is correct, the default convention is 'register' and can be changed to something else (like pascal or cdecl) with a command-line switch [2]. [1] http://www.freepascal.org/docs-html/prog/progse22.html [2] http://www.freepascal.org/docs-html/prog/progsu87.html Working through a simple example. I tried the cdecl option but for some reason i can compile but when i run my Gethello it cant find the shared library in the same folder? taylor@taylor-NE510:~/Projects/PASCAL$ ls Gethello Gethello.d hello.pas libhello.so taylor@taylor-NE510:~/Projects/PASCAL$ cat Gethello.d extern(C) void SubStr(); void main(){ SubStr(); } taylor@taylor-NE510:~/Projects/PASCAL$ cat hello.pas library subs; procedure SubStr(); cdecl; begin write('hello World'); end; exports SubStr; end. taylor@taylor-NE510:~/Projects/PASCAL$ nm libhello.so 3ac0 T SubStr taylor@taylor-NE510:~/Projects/PASCAL$ ./Gethello ./Gethello: error while loading shared libraries: libhello.so: cannot open shared object file: No such file or directory ===
Re: Can D interface with Free Pascal?
On Thursday, 28 January 2016 at 19:33:22 UTC, bearophile wrote: FreeSlave: On Thursday, 28 January 2016 at 08:15:38 UTC, FreeSlave wrote: Not directly. You can declare cdecl function on Free Pascal side and call it as extern(C). What about extern(Pascal)? https://dlang.org/spec/attribute.html#linkage Bye, bearophile Cool!, I did find this little gem. but still havent gotten a hello world to work. I need to figure out which libraries i need to include for fpc dependencies.
Can D interface with Free Pascal?
Just curious... I had a thought that perhaps since Objective C was a replacement for Pascal on the mac. that they might have the same interface. but I'm not savvy enough with fpc to figure out how to try it.
Re: Graphics/font/platform backends with common interfaces?
On Wednesday, 23 December 2015 at 23:34:58 UTC, Rikki Cattermole wrote: On 24/12/15 8:22 AM, Taylor Hillegeist wrote: [...] So far I've been implementing windowing and image libraries for Phobos. Right now windowing works on Windows minice eventing. Once eventing is done it is ready for the first stage of feedback. [...] How do you handle fonts?
Re: Graphics/font/platform backends with common interfaces?
On Wednesday, 23 December 2015 at 21:12:11 UTC, Taylor Hillegeist wrote: On Wednesday, 23 December 2015 at 21:07:12 UTC, Basile B. wrote: [...] Thanks for letting me know! So is what your saying is that an common interface is not possible or practical or perhaps useful? Also wouldn't the least common denominator be 2D FP in Retained Mode?
Re: Graphics/font/platform backends with common interfaces?
On Wednesday, 23 December 2015 at 21:07:12 UTC, Basile B. wrote: On Wednesday, 23 December 2015 at 20:52:05 UTC, Adam D. Ruppe wrote: [...] yes silly, more specially as - some of them are 2D with FP coordinates - some of them are 2D with integral coordinates - some of them are 2D with integral coordinates with transformation of the plan - some of them are 2D with integral coordinates without transformation of the plan - some of them are 3D FP float coordinates with transformation of the plan - some of them are in DirectMode, some of them not. - etc... So this would result in 5 or 6 templatized (because of the coord type) interface. IIRC Interfaces are not devirtualizables so that they can be extracted... also to put SDL and OPENGL on the same level is a bit strange. Thanks for letting me know! So is what your saying is that an common interface is not possible or practical or perhaps useful?
Re: Graphics/font/platform backends with common interfaces?
On Wednesday, 23 December 2015 at 20:57:27 UTC, Taylor Hillegeist wrote: On Wednesday, 23 December 2015 at 20:52:05 UTC, Adam D. Ruppe wrote: On Wednesday, 23 December 2015 at 20:49:21 UTC, Taylor Hillegeist wrote: | GRAPICS LIB | +---+---+---+ <- what is this interface |SDL|GDI|OPENGL.| +---+---+---+ SDL, GDI, and OpenGL *are* graphics libs so it seems a bit silly to put an interface there. I guess I'm thinking that to be able to switch between backends(gdi sdl) you use you must have a common interface. And if everyone had the same common interface it could be nice right? maybe this is more what I'm thinking. +-+ | USER APP| +-+ | GUI LIB | +-+ <- what is this interface |GenericGL| +-+ <- what is this interface |NativeGL | +-+
Re: Graphics/font/platform backends with common interfaces?
On Wednesday, 23 December 2015 at 20:52:05 UTC, Adam D. Ruppe wrote: On Wednesday, 23 December 2015 at 20:49:21 UTC, Taylor Hillegeist wrote: | GRAPICS LIB | +---+---+---+ <- what is this interface |SDL|GDI|OPENGL.| +---+---+---+ SDL, GDI, and OpenGL *are* graphics libs so it seems a bit silly to put an interface there. I guess I'm thinking that to be able to switch between backends(gdi sdl) you use you must have a common interface. And if everyone had the same common interface it could be nice right?
Re: Graphics/font/platform backends with common interfaces?
On Wednesday, 23 December 2015 at 20:23:25 UTC, rumbu wrote: On Wednesday, 23 December 2015 at 19:22:01 UTC, Taylor It was an initiative, but it looks abandoned now (Aurora Graphics): Thread: http://forum.dlang.org/thread/op.w9w0efr1707...@invictus.hra.local Source Code: https://github.com/auroragraphics/ I know I was excited when It was announced at DConf 2014. It really is too bad. what can be done now? how are standards defined around here for the benefit of the community? +---+ | USER APP| +---+ | GUI LIB | +---+ <- what is this interface | GRAPICS LIB | +---+---+---+ <- what is this interface |SDL|GDI|OPENGL.| +---+---+---+ But is there any standard interfaces?
Graphics/font/platform backends with common interfaces?
So I have seen alot of projects that need the same sort of stuff. graphics libraries gui libraries game libraries ploting libaries they would all benefit from a backend solution with a common interface for color fonts drawing pen_style aliasing etc. but each one i look at seems to have a built up solution with various degrees of integration with things like freetype gdi cairo sdl glew opengl. Shouldn't there be like a common (interface/abstract class) that these back-ends can fulfill? maybe I am unaware of how these things are done. And perhaps there are performance reasons that many of these are baked in. perhaps it should be like: standard color implementation. font interface that converts glyphs into drawing strokes. and a standard set of drawing instructions with transforms. //probably a grotesque simplification interface font_do{ glyphstrokes getstrokes(string characterstoget); } interface draw_do{ drawpixel(double x,double y); drawline(double x,double y); drawglyph(glypstrokes g); getpostdrawnsize(glypstroks g) ... other things }
Re: View Expanded Templates?
On Friday, 18 December 2015 at 18:35:40 UTC, Adam D. Ruppe wrote: On Friday, 18 December 2015 at 18:25:03 UTC, Taylor Hillegeist wrote: Is it possible to view the expanded form of templates or perhaps view the post-ctfe pre-compiled d code? I couldn't find any information on this topic but I think it would be useful. sometimes I use templates/mixins to write code for me but, sometimes i would rather have the expanded functions in the final versions. Check out my tip of the week from last month: http://arsdnet.net/this-week-in-d/nov-22.html If you just write out the string yourself instead of mixing it in, you can get a lot of progress on it. pragma(msg, code_generation_function()) simple + awesome. :)
View Expanded Templates?
Is it possible to view the expanded form of templates or perhaps view the post-ctfe pre-compiled d code? I couldn't find any information on this topic but I think it would be useful. sometimes I use templates/mixins to write code for me but, sometimes i would rather have the expanded functions in the final versions.
Re: Real Time-ing
On Tuesday, 8 December 2015 at 15:35:18 UTC, Taylor Hillegeist wrote: So, I mostly do programming that is of run to completion I took a stab at the problem: http://dpaste.dzfl.pl/2eef530d00fc 0 nsecs with jitter of :5 nsecs 498937256 nsecs with jitter of :1062744 nsecs 499036173 nsecs with jitter of :963827 nsecs 500025650 nsecs with jitter of :25650 nsecs 500020735 nsecs with jitter of :20735 nsecs 499057062 nsecs with jitter of :942938 nsecs 498932033 nsecs with jitter of :1067967 nsecs 591037317 nsecs with jitter of :91037317 nsecs 499032794 nsecs with jitter of :967206 nsecs 499034637 nsecs with jitter of :965363 nsecs 499022963 nsecs with jitter of :977037 nsecs 498976577 nsecs with jitter of :1023423 nsecs 499076723 nsecs with jitter of :923277 nsecs 499023885 nsecs with jitter of :976115 nsecs 499018048 nsecs with jitter of :981952 nsecs 499004224 nsecs with jitter of :995776 nsecs 499048461 nsecs with jitter of :951539 nsecs 499013747 nsecs with jitter of :986253 nsecs 499018048 nsecs with jitter of :981952 nsecs 499007604 nsecs with jitter of :992396 nsecs However i seem to get jitter of around 1 ms. Is there anything else i can do to improve?
Re: Real Time-ing
On Tuesday, 8 December 2015 at 15:50:35 UTC, Kagamin wrote: Oops, no. next+=dur; wait(next-now); call(); what calls does this use from the std library? to get the current time? Wait a amount of time?
Real Time-ing
So, I mostly do programming that is of run to completion verity. But I have a dream of calling functions periodically. So my question is: What is the best (most time accurate) way to call a function every n time units? What is the best way to measure the jitter of these calls? I'm also interested in waiting vs calling periodically eg. call wait(1 ms) call is not the same as 1 ms from call to call, due to the time duration of the function call. Thanks!
How will std.allocator change how we program in D?
I do not come from a c++ background. but have looked at what allocators do for c++. I know in D the standard for memory management is garbage collection and if we want to manage it ourselfs we have to do things like @nogc. I was just curious how the std allocator will change how we do things.
Re: Creating a DLL with a ActiveX interface.
On Wednesday, 16 September 2015 at 16:08:47 UTC, Taylor Hillegeist wrote: export extern (Windows) void SayHello(Variant *Input_Variant) { string A = "HELLO WORLD!"; Input_Variant.CA_VariantSetCString(A.ptr); } So I made a terrible error. Looking at http://lunesu.com/uploads/ModernCOMProgramminginD.pdf of the http://dlang.org/interface.html page I was given the impression that std.variant was a transparently equivalent to the com VARIANT. however: std.variant != VARIANT for com if anyone knows how to easily convert between the two i would be happy to know. I did find a nice library for VARIANT: https://github.com/JesseKPhillips/Juno-Windows-Class-Library
Re: Creating a DLL with a ActiveX interface.
On Monday, 14 September 2015 at 16:59:20 UTC, Adam D. Ruppe wrote: On Monday, 14 September 2015 at 15:44:36 UTC, Taylor Hillegeist wrote: So, Actually I am using NI LabVIEW to interact with my DLL. I imagine even getting hold of of that would troublesome or expensive. Ah, all right. Here's a SO thing (followed up by email then Fortunately I am working with Win7, And the below function seems to work beautifully. export extern (Windows) void SayHello(Variant *Input_Variant) { string A = "HELLO WORLD!"; Input_Variant.CA_VariantSetCString(A.ptr); } My goal was to store variants in an associative array Variant[string] and use this as a portable interpreter returning the resulting Variant. but that runs into some memory questions that I am not as savvy with. 1. Memory: I need to manage memory from the dll. I can give the caller a pointer to manage, but I don't think that is visible from gc. There should be different associtive arrays for different objects in the caller. How do I manage this? 2. Threads: I would like this to be as parallel as possible one objects call to its data should not hinder anothers. I have seen on the Memory managment page http://wiki.dlang.org/Win32_DLLs_in_D but I would like to know more.
Re: Creating a DLL with a ActiveX interface.
On Monday, 14 September 2015 at 15:20:50 UTC, Adam D. Ruppe wrote: On Monday, 14 September 2015 at 15:14:05 UTC, Taylor Hillegeist wrote: Gives a short example but the code doesn't compile for me. core\stdc\windows\com.d seems to be missing? I think the doc copy/pasted a typo there. It should be `core.sys.windows.com`. I've done some COM stuff with D before, getting it callable from vbscript and jscript. Can you tell me what steps you're using (in some detail, like are you using IE? or some other thing?) to test your thing? then I can try to make a working example that passes it and share that. So, Actually I am using NI LabVIEW to interact with my DLL. I imagine even getting hold of of that would troublesome or expensive. But I'm pretty savvy on that end. But for me its more about how to expose an com interface to the rest of the system through a dll.
Creating a DLL with a ActiveX interface.
So, I've looked at this topic of COM OLE and activeX, and found myself confused. http://dlang.org/interface.html Gives a short example but the code doesn't compile for me. core\stdc\windows\com.d seems to be missing? And i cant find any documentation on core\stdc on the standard library page. http://wiki.dlang.org/Win32_DLLs_in_D Points to "The Sample Code" under COM. but I find that confusing. So here is what I desire, You guys can let me know how dumb it is. I want a dll with an activex x interface, that contains a small bit if data a string for example. And this is what i want to happen? (caller sends activex object with string)->(my dll written in d minpulates string)->(caller gets a diffrent string) I call on the wisdom of the community to help me in this. Thanks!
Re: How to open a webpage in D?
On Monday, 31 August 2015 at 22:24:28 UTC, Adam D. Ruppe wrote: On Monday, 31 August 2015 at 22:21:20 UTC, Taylor Hillegeist wrote: I thought that perhaps spawing a process would work but Try the browse function from std.process: http://dlang.org/phobos/std_process.html#browse What it does is execute a browser process with the given argument. I think a filename will work as well as a url. Browse is obviously the coolest solution. :)
Re: How to open a webpage in D?
On Monday, 31 August 2015 at 22:21:20 UTC, Taylor Hillegeist wrote: I thought that perhaps spawing a process would work but execute("PATH TO HTML FILE",null,Config.none,size_t.max,dirName(exepath)); Didn't seem to work? any ideas? Actually executeShell worked for me thanks for the reference to Std.process.
How to open a webpage in D?
I thought that perhaps spawing a process would work but execute("PATH TO HTML FILE",null,Config.none,size_t.max,dirName(exepath)); Didn't seem to work? any ideas?
Re: Hello Assembly!
On Wednesday, 12 August 2015 at 22:32:30 UTC, Adam D. Ruppe wrote: On Wednesday, 12 August 2015 at 22:18:41 UTC, Adam D. Ruppe wrote: [...] Here's an example: [...] Wow, very cool thanks!
Re: Hello Assembly!
On Wednesday, 12 August 2015 at 22:18:41 UTC, Adam D. Ruppe wrote: On Wednesday, 12 August 2015 at 22:10:32 UTC, Taylor Hillegeist wrote: So i was playing around with the D inline assembly trying to make it say hello world on my windows setup... Have you ever written assembly for Windows before? Your code looks more like DOS (aside from the EAX, which would be overwriten by the AH mov anyway! In DOS, I think it was DX.) But DOS code won't work here anyway, since it was 16 bit and D makes 32 or 64 bit exes. The way you'd typically do it on Windows is to just call one of the win32 api functions, similarly to how you'd do it from C or regular D, just calling the functions manually. Ahh, It probably is! I was looking for a minimal example. DOS != Windows CMD I was following the example on http://web.archive.org/web/20100529113659/http://home.comcast.net/~fbkotler/clueless.html It is werid working with asm on windows... RISC/asm is much more fimilar to me..
Re: Hello Assembly!
On Wednesday, 12 August 2015 at 22:14:58 UTC, Justin Whear wrote: On Wed, 12 Aug 2015 22:10:30 +, Taylor Hillegeist wrote: I figure this should do it. but i'm running into problems. Anybody know why? Describe "problems" object.Error@(0): Access Violation 0x00402028 0x38004023 0x6C0018FF 0x38004023 0xE50018FF 0xA1004022 0x010041E0 0x3800 0x5C0018FF 0x3801 0xD00018FF 0xF40100FD 0x780018FD 0x1E0018FF Thats pretty much it!
Hello Assembly!
So i was playing around with the D inline assembly trying to make it say hello world on my windows setup... void main(){ asm { myhello: db "HELLO, WORLD$"; mov EAX , myhello; mov AH, 0x09; int 0x21; } } I figure this should do it. but i'm running into problems. Anybody know why?
Re: How to get *32mscoff libraries for phobos?
On Thursday, 23 July 2015 at 15:39:15 UTC, Taylor Hillegeist wrote: On Thursday, 23 July 2015 at 15:23:07 UTC, Taylor Hillegeist wrote: I found this nugget in the sc.ini file! [Environment32mscoff] LIB="%@P%\..\lib32mscoff" Apparently i need to create a lib32mscoff folder in C:\D\dmd2\windows\ Well if its not one thing its always another :) LINK : fatal error LNK1104: cannot open file 'LIBC.lib' This file is not on my computer... In recent versions of VC it has been replaced with LIBCMT.lib (multi-thread). So not really sure what the right thing is to do here. LOL... I copied LIBCMT.lib and renamed it LIBC.lib and it worked... so if it works? Thanks everyone!
Re: How to get *32mscoff libraries for phobos?
On Thursday, 23 July 2015 at 15:23:07 UTC, Taylor Hillegeist wrote: I found this nugget in the sc.ini file! [Environment32mscoff] LIB="%@P%\..\lib32mscoff" Apparently i need to create a lib32mscoff folder in C:\D\dmd2\windows\ Well if its not one thing its always another :) LINK : fatal error LNK1104: cannot open file 'LIBC.lib' This file is not on my computer... In recent versions of VC it has been replaced with LIBCMT.lib (multi-thread). So not really sure what the right thing is to do here.
Re: How to get *32mscoff libraries for phobos?
On Thursday, 23 July 2015 at 14:56:48 UTC, Taylor Hillegeist wrote: On Thursday, 23 July 2015 at 01:43:56 UTC, Mike Parker wrote: [...] IT worked! Placing this Batch file in the dmd2\src Folder. -- BEGIN FILE: BUILD.bat set dm_make=C:\D\dmd2\windows\bin\make.exe set DMD=C:\D\dmd2\windows\bin\dmd.exe set cl32=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\cl.exe set ar32=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\lib.exe [...] I found this nugget in the sc.ini file! [Environment32mscoff] LIB="%@P%\..\lib32mscoff" Apparently i need to create a lib32mscoff folder in C:\D\dmd2\windows\
Re: How to get *32mscoff libraries for phobos?
On Thursday, 23 July 2015 at 01:43:56 UTC, Mike Parker wrote: On Thursday, 23 July 2015 at 01:39:05 UTC, Mike Parker wrote: post at [1] where Rainer shared the relevant bits of a batch Gah, hate it when I forget the links. [1] http://forum.dlang.org/post/m456t5$2jc4$1...@digitalmars.com IT worked! Placing this Batch file in the dmd2\src Folder. -- BEGIN FILE: BUILD.bat set dm_make=C:\D\dmd2\windows\bin\make.exe set DMD=C:\D\dmd2\windows\bin\dmd.exe set cl32=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\cl.exe set ar32=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\lib.exe cd druntime del /q errno_c.obj complex.obj %dm_make% -f win64.mak DMD=%DMD% MODEL=32mscoff "CC=\"%cl32%\"" if errorlevel 1 goto xit cd .. cd phobos cd etc\c\zlib %dm_make% -f win64.mak clean cd ..\..\.. %dm_make% -f win64.mak DMD=%DMD% MODEL=32mscoff "CC=\"%cl32%\"" MAKE=%dm_make% "AR=\"%ar32%\"" if errorlevel 1 goto xit cd .. -- END FILE I had to reinstall dmd (I think I messed up my dmd2\src folder somehow) I used visual studio 2013 community edition. SO. Where do i put it now that its built? I placed it in the dmd2\windows\lib and i still got LINK : fatal error LNK1104: cannot open file 'phobos32mscoff.lib' ... perhaps i need to edit the sc.ini file...
How to get *32mscoff libraries for phobos?
I have tried to build this and failed miserably. I have some questions? What make do you use? digital mars, gnu. what tools do you need? is it possible? I also failed to build zlib32coff.lib make[2]: *** No rule to make target `zlib32mscoff.lib'. Stop. I could say more but it probably wouldn't be useful.
Re: access violation With dll?
On Thursday, 16 July 2015 at 17:28:52 UTC, jklp wrote: On Thursday, 16 July 2015 at 17:22:50 UTC, jklp wrote: On Thursday, 16 July 2015 at 17:04:09 UTC, Taylor Hillegeist wrote: [...] Your proto is wrong. Your forgot the FFI convention (__cdecl = extern(C)). Try this instead: --- extern(C) alias Proto = void function(char*, int); Proto func = cast(Proto) GetProcAddress(h, "Test"); if (func) { char[] STUFF; STUFF.length = 5000; func (STUFF.ptr , STUFF.length); // prints etc... } Also i guess that the dll returns a null terminated string so the result has to be read like this: --- import std.string; printf("%s\n", fromStringz(STUFF.ptr)); --- Otherwise you'll get a random output after the 'HELLO WORLD'. (wait maybe the console will automatically cut... ?) Hey that was very useful. Thank you both! Also if you have any good resources regarding this topic I would be interested.
access violation With dll?
Beleive it or not the code below does work. However I get an access violation after every run? any Ideas why? +Code to Run DLL function+++ import core.runtime; import std.stdio; import core.memory; import std.c.windows.windows; int main() { HMODULE h; FARPROC fp; printf("Start Dynamic Link...\n"); h = cast(HMODULE) Runtime.loadLibrary("SharedLib.dll"); void function(ref char[], int) Testf = cast(void function(ref char[], int)) GetProcAddress(h, "Test"); //Function Says HELLO WORLD char[] STUFF; STUFF.length = 5000; Testf( STUFF , STUFF.length); printf("%s\n", (&STUFF)); //PRINTS HELLO WORLD Runtime.unloadLibrary(h); printf("End...\n"); return 0; } ++END CODE+++ the function header has this line: void __cdecl Test(char MyOutput[], int32_t len); and i get this Error: object.Error@(0): Access Violation 0x77206568 0x646C726F 0x00405A2C in int object.ModuleInfo.opApply(scope int delegate(object.ModuleInfo*)) 0x0040222C in main 0x00414949 in mainCRTStartup 0x7678337A in BaseThreadInitThunk 0x770592E2 in RtlInitializeExceptionChain 0x770592B5 in RtlInitializeExceptionChain To be honest I was surprised this worked, since i am fairly unfamiliar to linking to dlls.
Re: Same process to different results?
On Wednesday, 1 July 2015 at 17:00:51 UTC, Taylor Hillegeist wrote: When I run the code (compiled on DMD 2.067.1): -- import std.algorithm; import std.stdio; import std.range; string A="AaA"; string B="BbBb"; string C="CcCcC"; void main(){ int L=25; int seg1len=(L-B.length)/2; int seg2len=B.length; int seg3len=L-seg1len-seg2len; (A.cycle.take(seg1len).array ~B.cycle.take(seg2len).array ~C.cycle.take(seg3len).array).writeln; string q = cast(string) (A.cycle.take(seg1len).array ~B.cycle.take(seg2len).array ~C.cycle.take(seg3len).array); q.writeln; } --- I get a weird result of AaAAaAAaAABbBbCcCcCCcCcCC A a A A a A A a A A B b B b C c C c C C c C c C C Any ideas why? Some way or another the type was converted to a dchar[] during this process: A.cycle.take(seg1len).array ~B.cycle.take(seg2len).array ~C.cycle.take(seg3len).array Why would it change the type so sneaky like?... Except for maybe its the default behavior with string due to 32bits => (typically one grapheme)? I bet cycle did this.
Re: Same process to different results?
On Wednesday, 1 July 2015 at 17:06:01 UTC, Adam D. Ruppe wrote: I betcha it is because A, B, and C are modified by the first pass. A lot of the range functions consume their input. Running them one at a time produces the same result. for some reason: (A.cycle.take(seg1len).array ~B.cycle.take(seg2len).array ~C.cycle.take(seg3len).array).writeln; is different from: string q = cast(string) (A.cycle.take(seg1len).array ~B.cycle.take(seg2len).array ~C.cycle.take(seg3len).array); q.writeln; I was wondering if it might be the cast?
Same process to different results?
When I run the code (compiled on DMD 2.067.1): -- import std.algorithm; import std.stdio; import std.range; string A="AaA"; string B="BbBb"; string C="CcCcC"; void main(){ int L=25; int seg1len=(L-B.length)/2; int seg2len=B.length; int seg3len=L-seg1len-seg2len; (A.cycle.take(seg1len).array ~B.cycle.take(seg2len).array ~C.cycle.take(seg3len).array).writeln; string q = cast(string) (A.cycle.take(seg1len).array ~B.cycle.take(seg2len).array ~C.cycle.take(seg3len).array); q.writeln; } --- I get a weird result of AaAAaAAaAABbBbCcCcCCcCcCC A a A A a A A a A A B b B b C c C c C C c C c C C Any ideas why?
Best way to count character spaces.
So I am aware that Unicode is not simple... I have been working on a boxes like project http://boxes.thomasjensen.com/ it basically puts a pretty border around stdin characters. like so: /\ \ \_|Different all twisty a| |of in maze are you, | |passages little. | | ___|_ \_/_/ but I find that I need to know a bit more than the length of the string because of encoding differences I had a thought at one point to do this: MyString.splitlines.map!(a => a.toUTF32.length).reduce!max(); Should get me the longest line. but this has a problem too because control characters might not take up space (backspace?). https://en.wikipedia.org/wiki/Unicode_control_characters leaving an unwanted nasty space :( or take weird amount of space \t. And perhaps the first isn't really something to worry about. Or should i do something like: MyString.splitLines .map!(a => a .map!(a => a .isGraphical) .map!(a => cast(int) a?1:0) .array .reduce!((a,b) => a+b)) .reduce!max Mostly I am just curious of best practice in this situation. Both of the above fail with the input: "hello \n People \nP\u0008ofEARTH" on my command prompt at least.
Re: is eC alot like D?
On Wednesday, 11 March 2015 at 03:55:21 UTC, Rikki Cattermole wrote: On 11/03/2015 4:16 p.m., Taylor Hillegeist wrote: So I found http://ec-lang.org/ it seems alot like D, But it has a company backing it. It just seems interesting. There is almost no meta programming support. Let alone CTFE. And no generics in the form of e.g. Java's is not the same as D's meta-programming support. Yes, D is a very powerful language with a boatload of features. eC almost seems like a subset. but what I find fascinating is the infrastructure built around it. Of course when someone's full time job is to build infrastructure, I tends to happen more predictably. But like all things in life you have to take the good, and carry it with you into the future. I bet there is alot we can learn from eC. I wonder how compatible the two languages are, I have been experimenting with language to language porting techniques, every language is in similar in some way to another, but to varying degrees.
is eC alot like D?
So I found http://ec-lang.org/ it seems alot like D, But it has a company backing it. It just seems interesting.
Re: Int to float?
On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: Am 05.03.2015 um 21:00 schrieb Taylor Hillegeist: How to I cast a Int to float without changing its binary representation? int someValue = 5; float sameBinary = *(cast(float*)cast(void*)&someValue); ahh of course! lol :)
Int to float?
How to I cast a Int to float without changing its binary representation?
Re: Compiling dll issue.
On Monday, 25 August 2014 at 15:09:59 UTC, Taylor Hillegeist wrote: So i have been trying to follow the instructions on: http://wiki.dlang.org/Win32_DLLs_in_D but when i get to the step where i compile the dll dmd -ofmydll.dll -L/IMPLIB mydll.d dll.d mydll.def I get this output: OPTLINK (R) for Win32 Release 8.00.15 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html OPTLINK : Error 180: No Match Found for Export/ENTRY - : DllGetClassObject OPTLINK : Error 180: No Match Found for Export/ENTRY - : DllCanUnloadNow OPTLINK : Error 180: No Match Found for Export/ENTRY - : DllRegisterServer OPTLINK : Error 180: No Match Found for Export/ENTRY - : DllUnregisterServer OPTLINK : Error 81: Cannot EXPORT : DllCanUnloadNow OPTLINK : Error 81: Cannot EXPORT : DllGetClassObject OPTLINK : Error 81: Cannot EXPORT : DllRegisterServer OPTLINK : Error 81: Cannot EXPORT : DllUnregisterServer --- errorlevel 8 Not, very pretty. Do I have something not setup right? Im using the latest DMD as of 8/25/2014. 2.066.0 Any Ideas? So, I figured it out! I used the wrong example for mydll.def. - LIBRARY MYDLL DESCRIPTION 'My DLL written in D' EXETYPE NT CODEPRELOAD DISCARDABLE DATAWRITE EXPORTS DllGetClassObject @2 DllCanUnloadNow @3 DllRegisterServer @4 DllUnregisterServer @5 -- The above will cause errors: even though it makes you think that it should be mydll.def it is not. -- LIBRARY "mydll.dll" EXETYPE NT SUBSYSTEM WINDOWS CODE SHARED EXECUTE DATA WRITE -- The above is the correct .def contents Thanks all!
Compiling dll issue.
So i have been trying to follow the instructions on: http://wiki.dlang.org/Win32_DLLs_in_D but when i get to the step where i compile the dll dmd -ofmydll.dll -L/IMPLIB mydll.d dll.d mydll.def I get this output: OPTLINK (R) for Win32 Release 8.00.15 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html OPTLINK : Error 180: No Match Found for Export/ENTRY - : DllGetClassObject OPTLINK : Error 180: No Match Found for Export/ENTRY - : DllCanUnloadNow OPTLINK : Error 180: No Match Found for Export/ENTRY - : DllRegisterServer OPTLINK : Error 180: No Match Found for Export/ENTRY - : DllUnregisterServer OPTLINK : Error 81: Cannot EXPORT : DllCanUnloadNow OPTLINK : Error 81: Cannot EXPORT : DllGetClassObject OPTLINK : Error 81: Cannot EXPORT : DllRegisterServer OPTLINK : Error 81: Cannot EXPORT : DllUnregisterServer --- errorlevel 8 Not, very pretty. Do I have something not setup right? Im using the latest DMD as of 8/25/2014. 2.066.0 Any Ideas?
Re: Nameless Static Array
On Thursday, 12 June 2014 at 16:02:18 UTC, Adam D. Ruppe wrote: On Thursday, 12 June 2014 at 15:58:25 UTC, Taylor Hillegeist wrote: But without the NEW strategy. I must allocate static arrays and set them to a pointer in my struct. Not too big of deal really. Have you considered just making the buffer a struct member? I have indeed! I am considering having different sized arrays for the buffer. I just figured that meant having different structs with various sizes.
Nameless Static Array
So, Lately I have been avoiding the NEW keyword. I have recently given up static allocation of classes using CTFE. I guess they must be const or immutable? So naturally i can do most of what i need to with structs. They are statically allocated no NEW necessary. But without the NEW strategy. I must allocate static arrays and set them to a pointer in my struct. Not too big of deal really. uint[12] Buffer; R_R_Buffer RRB=R_R_Buffer(Buffer); uint[24] OtherBuffer; R_R_Buffer RRB2 = R_R_Buffer(OtherBuffer); I feel though i might end up having OtherOtherOtherBuffers, and it pollutes my local symbols. I just dont like it. Is there a way to not give the buffer a name and do lika dis: R_R_Buffer RRB=R_R_Buffer(uint[12]); R_R_Buffer RRB2 = R_R_Buffer(uint[24]); This obviously fails to compile, but i think you get the idea. Mostly, I don't care what the static array name is.
Re: modulo Strangeness?
On Wednesday, 11 June 2014 at 22:38:02 UTC, Taylor Hillegeist wrote: On Wednesday, 11 June 2014 at 22:35:39 UTC, Taylor Hillegeist wrote: On Wednesday, 11 June 2014 at 22:32:45 UTC, Taylor Hillegeist wrote: I have a simpleish bit of code here that always seems to give me an error, and i can't figure out quite why. If I have a constant 43 in the modulo if breaks. however if i use points.length it seems to be ok? import std.stdio; void main(){ int points[43] = [0, 1153, 1905, 1996, 1392, 305, -888,-1773,-2041,-1600, -603, 603, 1600,2041, 1773, 888, -305,-1392,-1996,-1905,-1153, -0,1153, 1905, 1996, 1392,305, -888,-1773,-2041,-1600, -603, 603, 1600, 2041, 1773, 888, -305,-1392,-1996,-1905,-1153,0]; foreach(int x; points){ writeln("List Value: ",points[(x%43)],"\t"); } } Perhaps i am stupid 0..points.length lol? i've been looking at this too long. foreach(uint x; points){ writeln("List Value: ",points[(x%43)],"\t"); } this must work because its a different type than an element in points[] Negative indexes are possible with modulo... that is why i am getting breaking... sorry all.
Re: modulo Strangeness?
On Wednesday, 11 June 2014 at 22:35:39 UTC, Taylor Hillegeist wrote: On Wednesday, 11 June 2014 at 22:32:45 UTC, Taylor Hillegeist wrote: I have a simpleish bit of code here that always seems to give me an error, and i can't figure out quite why. If I have a constant 43 in the modulo if breaks. however if i use points.length it seems to be ok? import std.stdio; void main(){ int points[43] = [0, 1153, 1905, 1996, 1392, 305, -888,-1773,-2041,-1600, -603, 603, 1600,2041, 1773, 888, -305,-1392,-1996,-1905,-1153, -0,1153, 1905, 1996, 1392,305, -888,-1773,-2041,-1600, -603, 603, 1600, 2041, 1773, 888, -305,-1392,-1996,-1905,-1153,0]; foreach(int x; points){ writeln("List Value: ",points[(x%43)],"\t"); } } Perhaps i am stupid 0..points.length lol? i've been looking at this too long. foreach(uint x; points){ writeln("List Value: ",points[(x%43)],"\t"); } this must work because its a different type than an element in points[]
Re: modulo Strangeness?
On Wednesday, 11 June 2014 at 22:32:45 UTC, Taylor Hillegeist wrote: I have a simpleish bit of code here that always seems to give me an error, and i can't figure out quite why. If I have a constant 43 in the modulo if breaks. however if i use points.length it seems to be ok? import std.stdio; void main(){ int points[43] = [0, 1153, 1905, 1996, 1392, 305, -888,-1773,-2041,-1600, -603, 603, 1600,2041, 1773, 888, -305,-1392,-1996,-1905,-1153, -0,1153, 1905, 1996, 1392,305, -888,-1773,-2041,-1600, -603, 603, 1600, 2041, 1773, 888, -305,-1392,-1996,-1905,-1153,0]; foreach(int x; points){ writeln("List Value: ",points[(x%43)],"\t"); } } Perhaps i am stupid 0..points.length lol? i've been looking at this too long.
modulo Strangeness?
I have a simpleish bit of code here that always seems to give me an error, and i can't figure out quite why. If I have a constant 43 in the modulo if breaks. however if i use points.length it seems to be ok? import std.stdio; void main(){ int points[43] = [0, 1153, 1905, 1996, 1392, 305, -888,-1773,-2041,-1600, -603, 603, 1600,2041, 1773, 888, -305,-1392,-1996,-1905,-1153, -0,1153, 1905, 1996, 1392,305, -888,-1773,-2041,-1600, -603, 603, 1600, 2041, 1773, 888, -305,-1392,-1996,-1905,-1153,0]; foreach(int x; points){ writeln("List Value: ",points[(x%43)],"\t"); } }
Re: Objects(from classes) at Compile time? no gc
On Saturday, 17 May 2014 at 13:21:29 UTC, Marc Schütz wrote: On Friday, 16 May 2014 at 22:48:08 UTC, Taylor Hillegeist wrote: Although, I don't know if it will allocate it during runtime as well. It will not. -Steve Does this work in GDC? Can't test in GDC, but it does work in LDC, and I see no reason why it shouldn't, because this functionality is implemented in the frontend, which DMD, GDC and LDC share. I've been trying to get a baremetal GDC working for the ARM cortex-M, I guess it isn't quite ready yet. I'm looking forward to DConf 2014 to seeing, "Tiny, Ubiquitous Machines Powered by D" by Michael V. Franklin. To see how his work on the cortex-M is going. I mostly work on safety critical applications DO-170C,(Nothing with D) but this language looks like it might have a great deal of potential in this area. Not that C isn't good, but there are things that make the code look cleaner. I was looking at the Interactive D compiler and how it associated the assembly code with the lines of D code, I guess you can do that through the link file(-S in gcc). But D has code coverage information, unit test that you don't have to remove from the production code. there is a great deal of good stuff there. more and more tools for various operation seem to pop up every day. good stuff.
Re: Objects(from classes) at Compile time? no gc
On Friday, 16 May 2014 at 14:13:28 UTC, Steven Schveighoffer wrote: On Fri, 16 May 2014 02:31:18 -0400, Jacob Carlborg wrote: On 16/05/14 06:59, Taylor Hillegeist wrote: The subject says it all really. i have this example: import core.memory; class fruit{ int value=5; public int getvalue(){ return value; } } int main(string[] args) { GC.disable; static fruit myfruit; return myfruit.getvalue(); } Most of the smart people will see that i want the program to return 5 but I did something dumb and didn't put in the "new" statement? So my question is in longer words "Can I create instances of objects at compile time?" and if not "why not, i could build something (roughly)equivalent out of structs and functions and have it at compile time?" If you create an immutable instance it's possible to create it at compile time: int main(string[] args) { GC.disable; immutable fruit myfruit = new immutable(fruit); pragma(msg, myfruit.getvalue); // will print 5 at compile time return myfruit.getvalue(); } Although, I don't know if it will allocate it during runtime as well. It will not. -Steve Does this work in GDC?
Objects(from classes) at Compile time? no gc
The subject says it all really. i have this example: import core.memory; class fruit{ int value=5; public int getvalue(){ return value; } } int main(string[] args) { GC.disable; static fruit myfruit; return myfruit.getvalue(); } Most of the smart people will see that i want the program to return 5 but I did something dumb and didn't put in the "new" statement? So my question is in longer words "Can I create instances of objects at compile time?" and if not "why not, i could build something (roughly)equivalent out of structs and functions and have it at compile time?"
Re: dxl (the d port of jexcelapi)
By the way the weblink is: http://www.dsource.org/projects/dexcelapi
dxl (the d port of jexcelapi)
So i was thinking i wonder if anyone has a d library for excel and behold there it was. however, it seems like d has grown since this was written. I'm getting bunches of errors telling me that i can't override a function without the override keyword. which is not a big deal, however I seem to be missing libraries. std.date; cannot be found :( is this equivalent to std.datetime? dcollections.LinkList; I found it but should i use It? is there not something in std.containers; that would replace it?
Re: Best way to check for an element in an array?
On Tuesday, 22 April 2014 at 03:57:33 UTC, Timothee Cour via Digitalmars-d-learn wrote: you can use stuff.canFind(2) but sometimes it'd be more convenient to have the other way around (UFCS chains etc); how about: bool isIn(T,T2...)(T needle, T2 haystack) if(__traits(compiles,T.init==T2[0].init)){ foreach(e;haystack){ if(needle==e) return true; } return false; } unittest{ assert(1.isIn(3,1,2) && !4.isIn(3,1,2)); } I like it! I didn't know you could use templates like that! Question though? why doesn't canFind() work on statically allocated arrays? import std.stdio; import std.algorithm; bool contains(T)( T[] haystack,T needle){ foreach(T e;haystack){ if(needle==e) return true; } return false; } unittest{ assert([3,1,2].contains(1) && ![3,1,2].contains(4)); } void main(string[] args) { int[3] stuff=[0,1,2]; if (stuff.contains(2)) { writeln("Hello World!"); } if (stuff.canFind(2)){ // No compile with stuff -> static writeln("This Also WOrks"); } } On Mon, Apr 21, 2014 at 8:25 PM, Taylor Hillegeist via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: So I find myself Doing this kind of thing very frequently. I have a Array of Somethings and i want to see if "something specific" is inside the array. I wrote a template for it. but is this the best way to do this kind of thing. I feel like it doesn't help with readability. Is there a better way? Maybe i missed something in the std library. import std.stdio; template FNDR(T){ bool isIn(T Element, T[] Array){ bool rtn=false; foreach(T ArrayElement; Array){ if(Element==ArrayElement){ rtn=true; } } return rtn; } } void main(string[] args) { int[3] stuff=[0,1,2]; if (FNDR!int.isIn(2,stuff)) { writeln("Hello World!"); } } Is there a way maybe to make it look like this? import std.stdio; template FNDR(T){ bool contains(T[] Array,T Element){ bool rtn=false; foreach(T ArrayElement; Array){ if(Element==ArrayElement){ rtn=true; } } return rtn; } } void main(string[] args) { int[3] stuff=[0,1,2]; if (stuff.contains(2)) // Much clean! stuff.FNDR!int.contains(2) doesn't work { writeln("Hello World!"); } } I'm interested in what you guys think? what is the cleanest way to do this?
Best way to check for an element in an array?
So I find myself Doing this kind of thing very frequently. I have a Array of Somethings and i want to see if "something specific" is inside the array. I wrote a template for it. but is this the best way to do this kind of thing. I feel like it doesn't help with readability. Is there a better way? Maybe i missed something in the std library. import std.stdio; template FNDR(T){ bool isIn(T Element, T[] Array){ bool rtn=false; foreach(T ArrayElement; Array){ if(Element==ArrayElement){ rtn=true; } } return rtn; } } void main(string[] args) { int[3] stuff=[0,1,2]; if (FNDR!int.isIn(2,stuff)) { writeln("Hello World!"); } } Is there a way maybe to make it look like this? import std.stdio; template FNDR(T){ bool contains(T[] Array,T Element){ bool rtn=false; foreach(T ArrayElement; Array){ if(Element==ArrayElement){ rtn=true; } } return rtn; } } void main(string[] args) { int[3] stuff=[0,1,2]; if (stuff.contains(2)) // Much clean! stuff.FNDR!int.contains(2) doesn't work { writeln("Hello World!"); } } I'm interested in what you guys think? what is the cleanest way to do this?