list comprehensions in FB?

General FreeBASIC programming questions.
Post Reply
ganache
Posts: 47
Joined: Aug 04, 2016 9:25

list comprehensions in FB?

Post by ganache »

I know that FB doesn't have any built-in syntax for list comprehensions like python or
some functional programming languages.
But can they be simulated. Examples would be nice.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: list comprehensions in FB?

Post by TJF »

You can embed Python code in FB code by compiling against libpython. Search the forum for details.
Imortis
Moderator
Posts: 1924
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: list comprehensions in FB?

Post by Imortis »

Moved to general as Tips & Tricks is for code examples, not questions.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: list comprehensions in FB?

Post by caseih »

A list comprehension is not simply a list structure. It's a syntax for building lists using functional programming. It's kind of like an SQL query really. In fact in C#, the Linq list comprehension mechanism is used to implement an SQL-like syntax for a variety of data operations.

And according to some wiki, there are even macro-based implementations of list comprehensions for C: https://rosettacode.org/wiki/List_comprehensions#C. I don't understand the C example at all and didn't spend much time looking at it. But I'm sure macros could work in FB also.
Lost Zergling
Posts: 538
Joined: Dec 02, 2011 22:51
Location: France

Re: list comprehensions in FB?

Post by Lost Zergling »

I designed this one : viewtopic.php?f=8&t=26533
Be welcome trying it.
Post Reply