Re: Range handling difficulties

2024-04-24 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 24, 2024 at 08:08:06AM +, Menjanahary R. R. via 
Digitalmars-d-learn wrote:
> I tried to solve Project Euler [problem
> #2](https://projecteuler.net/problem=2) using
> [Recurrence/recurrence](https://dlang.org/library/std/range/recurrence.html).
> 
> Assuming `genEvenFibonacci` is the appropriate funtion in Explicit
> form, I got what I need like so:
> 
> ```
> auto evenfib = recurrence!genEvenFibonacci(2uL, 8uL);
> 
> writeln;
> evenfib.take(11).sum.writeln;
> ```
> 
> But that's like cheating because there is no prior knowledge of `11`.
> 
> I just got it manually by peeking at the sequence `[2, 8, 34, 144,
> 610, 2584, 10946, 46368, 196418, 832040, 3524578, 14930352]`.
> 
> `14930352` must be filtered out because beyond the limit set!
> 
> How to fix that properly using all the standard library capabilities
> programatically?
> 
> I'm thinking of Range and/or std.algorithm.

evenfib.until!(n => n > 4_000_000).sum.writeln;


T

-- 
The trouble with TCP jokes is that it's like hearing the same joke over and 
over.


Re: mmap file performance

2024-04-24 Thread Patrick Schluter via Digitalmars-d-learn

On Monday, 15 April 2024 at 16:13:41 UTC, Andy Valencia wrote:
On Monday, 15 April 2024 at 08:05:25 UTC, Patrick Schluter 
wrote:
The setup of a memory mapped file is relatively costly. For 
smaller files it is a net loss and read/write beats it hands 
down.


Interestingly, this performance deficit is present even when 
run against the largest conveniently available file on my 
system--libQt6WebEngineCore.so.6.4.2 at 148 megs.  But since 
this reproduces in its C counterpart, it is not at all a 
reflection of D.


As you say, truly random access might play to mmap's strengths.


Indeed, my statement concerning file size is misleading. It's the 
amount of operations done on the file that is important. For 
bigger files it is normal to have more operations.
I have measurement for our system (Linux servers) where we have 
big index files which represent a ternary tree that are generally 
memory mapped. These files are several hundreds of megabytes big 
and the access is almost random. These files still grow but the 
growing parts are not memory mapped but accessed with pread() and 
pwrite() calls. Accesses via pread() take exactly twice the time 
from memory copy for reads of exactly 64 bytes (size of the 
record).




My real point is that, whichever API I use, coding in D was far 
less tedious; I like the resulting code, and it showed no 
meaningful performance cost.





Recommendations on porting Python to D

2024-04-24 Thread Chris Piker via Digitalmars-d-learn

Hi D

I have a somewhat extensive CGI based web service written in 
Python and I'd like to port it to D.  I can do this manually of 
course, and maybe that's the best way, but for a rough start, is 
anyone aware of any tools that generate an abstract syntax tree 
which could then be converted to somewhat equivalent D code?  
This might give me a jump-start on the manual conversion process. 
 Then later I can work on removing the CGI dependency.


I'm aware that this wouldn't work in general due to all the third 
party modules typically used in python, but most of this code is 
self contained Python2 and doesn't depend on many imports.


I can just call my old C code from D, but the old Python is 
another story.


Thanks for any advice you may have,




Re: Recommendations on porting Python to D

2024-04-24 Thread Lance Bachmeier via Digitalmars-d-learn

On Wednesday, 24 April 2024 at 19:50:45 UTC, Chris Piker wrote:

is anyone aware of any tools that generate an abstract syntax 
tree which could then be converted to somewhat equivalent D 
code?  This might give me a jump-start on the manual conversion 
process.  Then later I can work on removing the CGI dependency.


I haven't used Python much in recent years, but my recollection 
is that Python 2 had an ast module that would spit out the ast 
for you.


Re: Range handling difficulties

2024-04-24 Thread Menjanahary R. R. via Digitalmars-d-learn

On Wednesday, 24 April 2024 at 14:22:10 UTC, H. S. Teoh wrote:
On Wed, Apr 24, 2024 at 08:08:06AM +, Menjanahary R. R. via 
Digitalmars-d-learn wrote:

[...]


evenfib.until!(n => n > 4_000_000).sum.writeln;


T


Thanks a lot! You've made my day 


Re: Recommendations on porting Python to D

2024-04-24 Thread Tim via Digitalmars-d-learn

On Wednesday, 24 April 2024 at 19:50:45 UTC, Chris Piker wrote:
I have a somewhat extensive CGI based web service written in 
Python and I'd like to port it to D.  I can do this manually of 
course, and maybe that's the best way, but for a rough start, 
is anyone aware of any tools that generate an abstract syntax 
tree which could then be converted to somewhat equivalent D 
code?


My parser generator has an example with a grammar for Python: 
https://github.com/tim-dlang/dparsergen/tree/master/examples/python


Re: Print debug data

2024-04-24 Thread mw via Digitalmars-d-learn

On Monday, 17 July 2023 at 03:43:04 UTC, Alain De Vos wrote:

Is it possible to print runtime memory usage of:
-The stack
-The heap
-The garbage collector ?


And how to print the memory stats of each class / struct type?




Re: Recommendations on porting Python to D

2024-04-24 Thread Sergey via Digitalmars-d-learn

On Wednesday, 24 April 2024 at 19:50:45 UTC, Chris Piker wrote:

Hi D

I have a somewhat extensive CGI based web service written in


There is also https://code.dlang.org/packages/arsd-official%3Acgi


Re: Adapting foreign iterators to D ranges

2024-04-24 Thread cc via Digitalmars-d-learn

On Wednesday, 24 April 2024 at 05:08:25 UTC, Salih Dincer wrote:
Yes, `opApply()` works! You just need to use `do while()` 
instead of `while()` because it skips the first item.


It depends on the type of structure being consumed, if it 
provides "next" as a direct pointer then yeah you would need to 
consume the item first before iterating to the next in line.  
However some APIs provide an opaque iterator type where you call 
a "next" method to get the first element, IIRC Lua does something 
like this.


Re: Recommendations on porting Python to D

2024-04-24 Thread Chris Piker via Digitalmars-d-learn
On Wednesday, 24 April 2024 at 20:13:26 UTC, Lance Bachmeier 
wrote:
I haven't used Python much in recent years, but my recollection 
is that Python 2 had an ast module that would spit out the ast 
for you.


Thanks for the pointer! So I ran one of my modules through and 
generated an AST, and get results similar to:

```
Module(
   body=[
  Import(
 names=[
alias(name='sys')]),
  FunctionDef(
 name='pout',
 args=arguments(
posonlyargs=[],
args=[
   arg(arg='item')],
kwonlyargs=[],
kw_defaults=[],
defaults=[]),
 body=[
```
etc.

I presume I'll now need to write something that parses this into 
D source (maybe with the assistance of a module provided above).  
Before I do that, is this syntax general enough that a Python-AST 
to D source converter may already exist?  Obvious searches in 
google and the D package index didn't turn up anything.


I have no background at all in working with ASTs, in fact my 
formal education is not even in CS, so I'm way outside my 
wheelhouse at this point.






Range handling difficulties

2024-04-24 Thread Menjanahary R. R. via Digitalmars-d-learn
I tried to solve Project Euler [problem 
#2](https://projecteuler.net/problem=2) using 
[Recurrence/recurrence](https://dlang.org/library/std/range/recurrence.html).


Assuming `genEvenFibonacci` is the appropriate funtion in 
Explicit form, I got what I need like so:


```
auto evenfib = recurrence!genEvenFibonacci(2uL, 8uL);

writeln;
evenfib.take(11).sum.writeln;
```

But that's like cheating because there is no prior knowledge of 
`11`.


I just got it manually by peeking at the sequence `[2, 8, 34, 
144, 610, 2584, 10946, 46368, 196418, 832040, 3524578, 14930352]`.


`14930352` must be filtered out because beyond the limit set!

How to fix that properly using all the standard library 
capabilities programatically?


I'm thinking of Range and/or std.algorithm.