[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip / qa] [cm / hm / lgbt / y] [3 / aco / adv / an / asp / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / qst / sci / soc / sp / tg / toy / trv / tv / vp / wsg / wsr / x] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

[Advertise on 4chan]


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: Yegor.jpg (96 KB, 1280x720)
96 KB
96 KB JPG
What are you working on, /g/?

New interview with Dave West!
https://www.youtube.com/watch?v=UaxSDFesUR0

Last thread: >>78806049
>>
>>78813926
Lisp is the most powerful programming language.
>>
Nim
>haha it's as fast as C but with Pascal syntax

Crystal
>haha it's as fast as C but with Ruby syntax

Julia
>haha it's as fast as C but with Python syntax

Rust
>haha it's as fast as C but with reddit syntax

Then why in the FUCK is there no
>haha it's as fast as C but with BASIC syntax

?!?!?!?!?!?!?!?
>>
File: centrism.jpg (25 KB, 445x495)
25 KB
25 KB JPG
>>78813926
how too sort two vectors at the same time based on the values of one of them using Julia?
>>
>>78813926
is that smalltalk man?
>>
>>78813951
why would you want basic syntax
>>
>>78813951
>>haha it's as fast as C but with BASIC syntax
You could probably implement this with Nim.
>>
>>78813951
I wanted to try this
https://www.purebasic.com/documentation/
but
>paying for a programming language
>>
>>78813951
>ML is reddit
>>
>>78814028
Yes.
>>
>>78814028
???
rust looks nothing like ML
>>
>>78813951
AND
why the FUCK is there no
>haha it's as fast as C but with LISP syntax
?!?!?!?!?!?!?!
>>
>>78814011
qb64 maybe?
>>
>>78814045
>>haha it's as fast as C but with LISP syntax
https://www.call-cc.org/
or
https://github.com/carp-lang/Carp (this is more future possibility than reality right now)
>>
>>78814042
expressions and types, pattern matching and shiet
rust is more than just haha c but with syntax sugar
>>
>>78814045
That's just Lisp.
http://www.iaeng.org/IJCS/issues_v32/issue_4/IJCS_32_4_19.pdf
>>
>>78814045
>>78814060
also gambit, cyclone, chez...
>>
>>78814045
wasm wat format
>>
>>78814073
yeah, there's an abundance of performance-lisp flavors out there.
Racket might even be viable since it moved to chez as well
>>
>>78814064
that paper is comparing first c attempt with lisp code that was reworked many times for performance
>>
File: 1550165410351.png (150 KB, 415x377)
150 KB
150 KB PNG
>>78813973
BASIC is my ceiling
>>
>>78814099
That does not matter. What does matter is that the Lisp code is by definition as fast as C.
>>
C++ question here.

I am working through Stroustrup's PPP2 and have finished putting together the calculator he walks the reader through. One of the exercises is to implement a new feature, so I thought I'd add functions. Whereas the token stream originally only read from cin, I added an
istringstream
member called
function
which receives the result of a function application to allow it to be tokenized:

Token Token_stream::get()
{
if (full) { full = false; return buffer; }
char ch;
bool reading_from_keyboard = false;
if (function.rdbuf()->in_avail() == 0) {
reading_from_keyboard = true;
while (cin.get(ch) && isspace(ch)) if (ch == '\n') return Token(print);
}
else {
function >> ch;
}
switch (ch) {
// ... decide what to do with character ...
}
}


After having defined a function, the first application works perfectly but the second causes the program to abort. In following the execution of the program with the debugger, it seems that the second time round, even though my function application method correctly has my token stream set its
function
stream to the desired string via a method that uses
function.str(s)
(ie, for
f(x) = x+2
, f(6) correctly results in my token stream's
function
stream containing
6.00000+2
),
function >> ch
doesn't work and ch remains in its unitialised state with char -52. What is happening? Do I have to do something to my stream before reusing it?
>>
>>78814112
try fastbasic
>>
>>78814053
>qb64 maybe?
nah it's shite

> -It's slower than FreeBasic, and produces bigger executables
>Compiled programs need a bunch of DLL to work, so they can't be stand-alone
>There is no real console: the text mode is actually a graphic window (so copy&paste won't work on it)
>the BAS file is converted to C++, then compiled with GCC: in that way, compiling is very slow, and finding an error could be very hard.

http://back2basic.phatcode.net/?Issue-%231/Community-Article%3A-QB-Vs.-FB-Vs.-QB64
>>
>declarative code lisp
it feels so fricken weird
>>
I know C, but I wanna try a new language. I'm just so tired of undefined behaviour and want to try something a bit more high level.
Any suggestions that aren't C++?
>>
>>78814234
Common Lisp
>>
>>78814234
Zig, D, Crystal, Haskell, elixir etc
depends what kind of new lang you want and what you want to do with it
>>
>>78814234
Zig. Or C++ because, like it or not, it's still the best option for people coming from C.
>>
>>78814234
https://doc.rust-lang.org/book/
>>
File: 1605954690839.png (291 KB, 1176x3450)
291 KB
291 KB PNG
Cbros..... It's over..
>>
>>78814308
>binary size
You still can't beat C
>>
>>78814324
>binary size
not even a r*stlet, but who the fuck cares about this anymore.
>>
>>78814334
a time traveler from the 1970s
>>
>>78814308
now try with "safe" rust
>>
>>78814157
run your code in a debugger to find where the abort comes from, and the message it should give.
make sure to use the debug build, generally an abort should present a error box in msvc and you should press the "retry" button so that you get a "not responding" window where either VS IDE will automatically debug, or you have to press the debug button to open the VS IDE.
on linux or mingw you have to use gdb.
>>
>>78814252
shitty unix integration, great lang.
>>78814256
>>78814271
might go with zig as i have a bit of experience with it already. wish the c compatibility was complete already.
>>
File: 1605957536824.png (42 KB, 595x303)
42 KB
42 KB PNG
>>78814324
>>78814363
Brehs..
>>
How do I learn OOP ? There is only so much doing exercises and scripts in python will get you. I think I am ok language wise but I can't seem to go into actually making usefull software
>>
>>78814377
>shitty unix integration
No.
>>
>>78814363
why? is competing with unsafe C code so it only makes sense to also use unsafe in Rust
>>
>>78814377
>might go with zig as i have a bit of experience with it already. wish the c compatibility was complete already.
If you want a slightly safer C
https://dlang.org/spec/betterc.html might be worth a read
https://dlang.org/spec/interfaceToC.html
interop isn't as nice as Zig obviously, but it's pretty straight forward
>>
>>78814405
Learn CLOS.
>>
>>78814363
Only 2 of the Rust programs have unsafe in the code, pidigits and spectral norm.
>>
>>78814405
well, what do you want to make?
>>
>>78814410
make an executable under 50 mb for me.
>>
>>78814366
When I debug, this is the information I get, assuming f(x) = x+2, f(5) worked perfectly and I am attempting f(6):
1. my token stream's
function
stream correctly contains "6.000000+2";
2. at the
function >> ch
step ... nothing happens: ch remains in its uninitialised state (-52);
3. in the tokenizer, this causes
if (isalpha(ch))
to abort due to ch not being within the 0–255 range.

In other words, the key problem seems to be that
function >> ch
 doesn't correctly feed the content of my stream to ch. What could cause this input operation to fail?
>>
>languages that can do more compile-time assertions are faster
lmao, this is just like when C++ people discovered compile-time with constexpr
>>
(coerce 1.0 'integer)

>doesn't compile
let x = 1 :: Float
let y = unsafeCoerce x :: Int
y

>compiles, gives 5360320512
Lisp confirmed for safer than Haskell
>>
>>78814485
the stream could be in an error state, you could check using the operator bool(), (AKA if(stream >> value)).
To get a more detailed information, you could check .bad() for logical errors (conversion, etc), .fail() for logical errors + integrity errors (who knows what that means), and .eof() is not affect .bad() or .fail(), but it will affect .good() and operator bool().
>>
>>78814553
>state
yikes
>>
>>78814532
>let me do unsafe action
>WTF why did you let me do unsafe action?
what are you on about retard?
>>
>>78814455
a job
>>
>template metaprogram in continuation passing style
How bad of an idea is this
>>
>>78814572
it's like you're asking "how do I learn engineering and get a job?"
>>
>>78814553
Thank you, man — good() returns 1 in the first execution and 0 in the second. Finally I'm getting somewhere.
>>
rust solves error handling very elegantly, with proper tagged unions
c++, on the other hand, is retarded
>>
>>78814575
CPS is shit no matter what, however, implementing a novel concept using template metaprogramming will earn you a lot of imaginary internet points, I'd say go for it.
>>
>>78814567
>implying coerce is safe
>>
>>78814185
>try fastbasic
>FastBasic - Fast BASIC interpreter for the Atari 8-bit computers

Wut
>>
There is no sqt up, so I'll ask here instead, even though it's not quite programming:
Why does sqlite's logo have the Apache leaf?
>>
>>78814735
Feather, not leaf. Feather.
>>
>>78814553
Thank you so much — what was happening was that at the end of
function >> ch
, the stream's eofbit was being set to true which put the stream in a bad state for reuse. Calling clear() before storing the new string made it work.
>>
>>78814735
probably just a coincidence. its not the same feather used in both logos
>>
>>78814782
That makes sense, thanks.
>not the same feather
Pretty similar tho.
>>
>>78814532
let x = 1.0 as i32;

>compiles, gives 1
let x: i32 = i32::from(1.0).unwrap_or_default();

>error[E0277]: the trait bound `i32: From<{float}>` is not satisfied

based rust
>>
If I wanted to have a look at BASIC for fun where should I begin? What compiler would I use on Linux?
>>
>>78815033
i don't know
>>
>>78815033
I have no idea
>>
>>78815033
maybe try asking in /dpt/?
>>
File: Back2BASIC.png (144 KB, 502x1216)
144 KB
144 KB PNG
>>78815033
freebasic
see >>78814203
>>
>>78815091
I tried but they didn't know
>>
>>78815094
Thanks
>>
>>78813951
>Rust
>Reddit
>>
>>78815140
You called?
>>
>>78815140
Yes, Rust is reddit.
>>
>>78813951
>reddit syntax
>>
>>78814308
>she posted the best result instead of average
>>
>>78814308
>using clang
>>
>>78815184
someone has the average?
>>
>>78813926
A friend of mine wants me to help him scrape the title, description, thumbnail, and probably other metadata from his youtube videos because he wants to put them up on a website. He has thousands of videos.

Is this something I can do solely with the youtube API or do I need to scrape the website with something like Beautiful Soup? Anyone got experience scraping youtube?
>>
>>78813926
>What are you working on, /g/?
I finally did it /dpt/. I quit my job in programming and got a job in HVAC. I am finally free from the nightmare.
>>
>FINALLY MADE IT BOYS
>Scored my first IT job
>data science tho
>>
>>78815235
>he does it for free
>>
File: 1605959576024.png (182 KB, 689x2972)
182 KB
182 KB PNG
>>78815206
>using clang
What the heck, Rust is still better in about half the benchmarks even vs. gcc, AND its easier to write AND it has more ergonomic tooling.. Cniles I don't feel so good.
>>
>>78815153
>>78815176
mental illness
>>
>>78815242
jej
all jobs suck, not just programming
>>
>>78813951
thread ruined
>>
>>78815298
>she posts best results instead of averages again
>>
>>78815298
>that difference in memory for n-body
Jesus Christ what the fuck.
>>
>>78813926
>What are you working on, /g/?
Task execution toolkit for sql scripts. Kind of make, but for sql.
>>
>>78815298
The 1.48 benchmarks are broken for anything using rayon.

>It looks like the Rayon library was not fully updated correctly after the benchmarksgame site upgraded to Rust 1.48, which broke all the Rust programs that depend on Rayon. This means that some of the fastest Rust programs are not included in the Rust 1.48 benchmarks. I'm working with the developer of the site to fix this.
>In other words, the Rust programs didn't get any slower, but the new comparison is using different Rust programs than the old one.
https://users.rust-lang.org/t/why-rust-1-48-0-is-slow/51756/14
>>
whats the point of using linked lists if vectors are faster in 99% of all use cases? why do so many functional languages default to linked lists if they are so painfully slow?
>>
>>78815430
They default to slower by default by guaranteeing TCO and boxing everything. Performance is not a goal for FP langs.
>>
>>78815298
>Make Error
>>
>>78815430
Just use a language that has both, like Lisp.
>>
>>78815430
linked lists are nice garbage collectors.
instead of freeing memory, you could just link it into a garbage list, and use that list when you need memory, and when the garbage is empty, you can call malloc. Usually with a single linked list.
Video games like using double linked lists in situations where it is a convenient way of implementing a save system. Where the list is never traversed through, until the game needs to be saved (but this can lead to slow saving).
>>
>>78815430
Linked lists are the backbone of most concurrent algorithms and data structures.
>>
>>78815541
>Video games like using double linked lists in situations where it is a convenient way of implementing a save system.
Source on this?
>>
>>78815555
now that's some wasted quads
>>
>>78815605
gamedevs like using shitty things like intrusive linked lists. remember too that gamedevs aren't a good place to look for inspiration since tons of them still write c++ like it's the 90s
>>
how do i convert this:
'x + 9y + 3z = 0'
into
'x+ 9*y + 3*z = 0'
>>
>>78815605
it stands to reason if you think about the problem. same thing for undo/redo's in applications and back/forward in browsers
>>
>>78815430
A linked list is one of the main data structures in the Linux kernel. Why? Vectors store their data in contiguous memory, for the kernel this is anywhere between "undesirable" and "literally impossible", linked list nodes may reside in wildly different places in memory.
>>
Is there any way to interpret C++?
I don't mean interpret the whole thing, I mean set up classes and functions before hand and start interpreting from the int main().
>>
>>78815661
break the string in terms, loop through each of them and treat them individually, concatenate
>>
>>78815702
but what happens if i don't separate terms with spaces?
>>
>>78815661
if it's only that string, do you not know regex?
>>
>>78815733
Remove all the spaces beforehand lmao, what do you need them for?
>>
>>78815661
If you want to impress your faggot teacher, write a recursive descent parser

https://www.youtube.com/watch?v=N55XNj8KjC4
>>
>>78815661
Depends on what you actually want to do. If you are writing a parser, tokenise the string, then you know where multiplies are implied to be.
>>
>>78813951
thread enhanced
>>
>>78815605
http://www.codeofhonor.com/blog/avoiding-game-crashes-related-to-linked-lists
>>
>>78815733
what separates the terms are the + signs, ignore the spaces
>>
FlexAir 5 just got released btw
I love lisp but i procrastinate on learning more
>>
>>78815828
a memory safe lang would have prevented this
>>
Is sixth normal form supposed to be a joke?
>>
File: nodehelp.png (9 KB, 758x325)
9 KB
9 KB PNG
Can I get some advice on this psuedo doubly linked list (?) in Java? I'm messing up on how to keep track of the Nodes above to assign them to the ones below.
>>
>>78815923
if current has next && current has bottom
if next has bottom
current.bottom.next = next.bottom
>>
File: job-interview.jpg (829 KB, 2048x1365)
829 KB
829 KB JPG
>ok, you have 10 minutes to efficiently implement dot product of 2 sparse vectors in your language of choice
your move anon?
>>
>>78816168
"nah I'm good"
>>
>>78816168
This isn't a difficult question.
>>
>>78816168
import solution from scipy
>>
>>78816196
I heard that it was often asked by Alexandrescu during his facebook years
>>
>>78816168
Order the two sparse vectors beforehand, use two pointers to go through each vectors.
>>
>>78816196
>answer "This isn't a difficult question."
>stay silent after that
>>
>>78816257
Based. Tell the interviewer he isn't qualified to interview you
>>
>>78816257
I don't know what type of sparse vector, so I can't progress further without first implementing one myself.
>>
>>78814334
The majority of computers all around you cares because they only have flash sizes on the order of 8-32K.
>>
>>78816168
How does them being sparse change the calculus?
>>
File: fragezeichenmädchen.jpg (109 KB, 500x500)
109 KB
109 KB JPG
Is there a way in Visual Studio Community to undo all the changes I made in the past half-hour in a solution or project or is local version control unavailable?
>>
>>78816287
you could have made a git bullshit thingymajig but you didnt so you cant
your best hope is CTRL+Z
>>
>>78816298
Fug, thanks.
>>
>>78816319
if you do make a git repository you still need to fuck around making commits and shit to revert them
>>
>>78814308

#[link(name = "gmp")]
extern "C" {
fn __gmpz_init_set_ui(rop: mpz_ptr, op: c_ulong);
fn __gmpz_clear(x: mpz_ptr);
fn __gmpz_get_ui(op: mpz_srcptr) -> c_ulong;
fn __gmpz_cmp(op1: mpz_srcptr, op2: mpz_srcptr) -> c_int;
fn __gmpz_add(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr);
fn __gmpz_mul_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong);
fn __gmpz_submul_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong);
fn __gmpz_addmul_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong);
fn __gmpz_tdiv_q(q: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr);


So the "rust code" is actually just a small front end to a C library, lol.
>>
>>78816287
CLion has this
>>
>>78816283
Naive algorithm performance for dot product of two vergy large & sparse vectors is bad.
>>
>>78816168
my job interview was pair programming a listbox in WPF and then go eat some fries with the (now) bois
>>
>>78816332
>no unsafe blocks
How do rust "programmers" defend this?
>>
>>78816364
that's hot desu
>>
>>78816168
sir this is a wendy's
>>
>>78814308
>not calculating mandelbrot shit in compile time using the one and only powerful C++ TMP lang
anon
>>
>>78816393
>zig.png
>*stands in your path*
>>
>>78816332
I'm not certain that that's the fastest one.

Benchmarksgame broke with the 1.48 update >>78815419
>>
>>78816168
Something like
struct sparse_vector_entry
{
unsigned long int pos;
double data;
}
class sparse_vector
{
public:
std::vector<sparse_vector_entry> entries;
void sort_vect()
{
std::sort(entries.begin(), entries.end(), [](sparse_vector_entry a, sparse_vector_entry b) {return a.pos > b.pos;});
}
}
double inn_prod(sparse_vector a, sparse_vector b)
{
a.sort_vect();
b.sort_vect();
double result = 0;
for (auto a_it = a.entries.begin(), auto b_it = b.entries.begin(); a_it != a.end() || b_it != b.end();)
{
if (a_it->pos == b_it->pos)
{
result += a_it->data * b_it->data;
}
else if (a_it->pos > b_it->pos)
{
b_it ++;
}
else
{
a_it++;
}
}
return result;
}

?
>>
main() {
int a, n;
printf("Enter a, n:");
scanf("%d %d", &a, &n);
printf("%d", a);
while (n--)
printf("0"); }
>>
>>78816426
Actually it's
a_it != a.end() && b_it != b.end()
, I always forget that .end() is after the end.
>>
>>78816426
>
{
stoppedreading
>>
so what's the likelihood of me not getting instantly dismissed, if i ask the interviewer to elaborate on "efficiently"?
>>
>>78816426
this is so fucking ugly man
>>
>>78816494
>"Oh, sorry, good catch, I forgot to mention. Efficient as in O(n+m) where m and n are the numbers of non-zero elements"
>>
>>78816448
main()                      {
int a, n ;
printf("Enter a, n:") ;
scanf("%d %d", &a, &n) ;
printf("%d", a) ;
while (n--)
printf("0") ;
printf("\n") ;}
>>
>>78816426
You need to work on making your code more readable.

>>78816257
Here is a solution in Python, but I assume the sparse vector is already sorted by index.

class SparseVector:
#Assumed sorted
def __init__(self, indices, values):
self.i = indices
self.v = values


def dot(a, b):
res = 0
aInd = 0
aS = len(a.i)
bInd = 0
bS = len(b.i)
while aInd < aS and bInd < bS:
while b.i[bInd] < a.i[aInd]:
bInd += 1
if bInd >= bS:
return res
if a.i[aInd]<b.i[bInd]:
aInd += 1
continue
res += a.v[aInd] * b.v[bInd]
bInd += 1
aInd += 1
return res
>>
>>78816362
What is the "proper" way of doing it? I can see iterating through and using a hashmap or vector to store a tuple of index and element, then iterate through the other vector multiplying if there's a match, or storing that in it's own collection. Or zipping them together and reducing the result, I'd benchmark to see which worked faster because I feel like the theoretical best answer doesn't actually perform the best.
>>
>>78814398
Tnhat's literally not even possible
>>
>>78816480
Eat shit and die.
>>78816499
Bro, I...
I know, I didn't do it particularly in a hurry, but I wasn't giving the variables good names either.
>>
>>78816542
main() {
int a, n
;
printf("Enter a, n:")
;
scanf("%d %d", &a, &n)
;
printf("%d", a)
;
while (n--)
printf("0")
;
printf("\n")
;
}
>>
>>78816566
cope
>>
>>78816340
Shame they don't provide a free version the way they do for IntelliJ. I really enjoyed using IntelliJ IDEA compared to Visual Studio Community, at least as far as the text editor is concerned.
>>
>>78815430
>whats the point of using linked lists if vectors are faster in 99% of all use cases?
Linked List is the simpler node based structure(dynamic resize without delete/create whole new Vectors/Array).

> why do so many functional languages default to linked lists if they are so painfully slow?
Easy and pretty for a lot data manipulation algorithms and a lot FP research happens in 80s 90s meaning low speed CPU for RAM speed.
>>
>>78816575
Seethe
>>
File: B7jpg.jpg (109 KB, 1271x482)
109 KB
109 KB JPG
>>78816287
>>78816298
>knowledgeless freetards
oof

https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.AutoHistory

Or if you wanna use git
Download and install Git Extensions.

https://github.com/gitextensions/gitextensions/releases

https://github.com/Arch/AutoHistory

Then, once your repository is opened in GitExtensions, go to the menu item: "Repository" -> "Git Maintenance" -> "Recover lost objects"...

There, uncheck "Show commits and tags" (that will check "Show other objects")

Now, when you double-click on a line, you should be able to get the content of the files created from the more recent to the oldest.
>>
>>78816597
Thanks. I did search around but all the answers I could find were for online version control.
>>
>>78816551
I doubt zipping would ever be faster, but the hashing method would work well for unsorted vectors.
>>
>>78816573
main() {
;int a, n
;printf("Enter a, n:")
;scanf("%d %d", &a, &n)
;printf("%d", a)
;while (n--)
printf("0")
;printf("\n")
;}
>>
File: digraph.png (27 KB, 1436x991)
27 KB
27 KB PNG
I just wrote a script that takes a json file and visualizes the schema with graphviz (genson -> pygraphviz). I'm assuming this is something people do quite often. What would you usually use? Does anyone know?
>>
>>78816644
looks too much like `;` is commenting out everything.
I forget which lang, but i know one actually uses `;` for comments.
>>
>>78816644
#define run ;
#define begin {
#define end ;}

main()
begin
run int a, n
run printf("Enter a, n:")
run scanf("%d %d", &a, &n)
run printf("%d", a)
run while (n--) printf("0")
run printf("\n")
end
>>
>>78816644
>t. Haskell programmer
>>
>>78816592
dilate
>>
>>78816684
>I forget which lang, but i know one actually uses `;` for comments.
Lisp
>>
What would g recommend for newcomer wanting to make graphical programs?
I am learning C and python so I am thinking about settling on python+pyqt5.
>>
Can someone help me write a C program that sums an array of command line arguement integers (no error checking necessary), and computes the sum with pipe and fork? I don't get how to write this pipe fork shit
>>
>>78816784
oh fug
why'd you have to remind me, i knew i erased that for good reason.
>>
>>78816787
c with your own gui toolkit
>>
Do Instagram filters use ML?
>>
>>78816572
Here is how I'd format that code:
#include <vector>
#include <algorithm>

class SparseVector{
public:
struct Entry{
size_t pos;
double data;
};

std::vector<Entry> entries;

void sort(){
std::sort(entries.begin(), entries.end(), [](Entry a, Entry b) {return a.pos > b.pos;});
};

auto begin() const{
return entries.begin();
};

auto end() const{
return entries.end();
};
};

double dot(SparseVector a, SparseVector b){
a.sort();
b.sort();

double result = 0;

for (auto aI = a.begin(), bI = b.begin(); aI != a.end() || bI != b.end();){
if (aI->pos == bI->pos){
result += aI->data * bI->data;
} else if (aI->pos > bI->pos){
++bI;
} else{
++aI;
}
}
return result;
};
>>
>>78816810
no
>>
>>78816811
>getting filtered by lisp
>>
>>78816847
I wanted to like Racket, but not even typed racket could do it for me.
>>
>>78816861
What style of syntax do you prefer?
>>
#define yeet throw
>>
>>78816870
ML
Nim is my current lang of choice because it's the closest I can have to ML
>>
>>78816842
>
} else{

Christ have mercy on your soul, this shit is horrible.
Cute variable names tho.
>>
>>78816707
What the actual fuck
>>
>>78816787
Use what you just mentioned: Python & Qt5
>>78816816
based sharkposter
>>
>>78816707
Are there any big/famous C projects that actually use #define like this??
>>
Can anyone explain the tower of hanoi recursive algorithm in a way that even a dimwit like me can understand? Thank you.
>>
>>78816969
the original bourne shell does this
>>
>>78816883
Why don't you just use an ML? Lack of support?
>>
>>78816707
Isn't the first 'run' unnecessary?
>>
>>78817111
not him but ML has been dead for a long time. F# is probably his best hope at this point
>>
>>78817111
my favourite an machine learning is haskell
>>
>>78817118
Why not Haskell or Idris?
>>
>>78817132
too much autism
>>
>>78817161
autism imageboard
>>
>>78816168
fn sparse_dot_product<'a>(mut a: &'a [i32], mut b: &'a [i32]) -> i32 {
if a.len() > b.len() {
core::mem::swap(&mut a, &mut b);
}
let mut a_map = a.iter().enumerate().filter(|(_, &x)| x != 0)
.map(|(x, &y)| (x, y)).collect::<std::collections::HashMap<usize, i32>>();
let mut b_map = b.iter().enumerate().take(a.len()).filter(|(_, &x)| x != 0)
.map(|(x, &y)| (x, y)).collect::<std::collections::HashMap<usize, i32>>();
if a_map.len() > b_map.len() {
core::mem::swap(&mut a_map, &mut b_map);
}
a_map.iter().fold(0, |mut acc, kv| {
if let Some(entry) = b_map.get(kv.0) {
acc += kv.1 * *entry;
}
acc
})
}

or the dumb way, would be curious to see how these compared
fn sparse_dot_product<'a>(mut a: &'a [i32], mut b: &'a [i32]) -> i32 {
if a.len() > b.len() {
core::mem::swap(&mut a, &mut b);
}
a.iter().zip(b.iter()).fold(0, |mut acc, (x, y)| {
acc += x * y;
acc
})
}
>>
>>78817161
I suppose there is OCaml too. Fancy a career in finance?
>>
>>78817111
i'm primarily into making games and don't want to worry about having to tune GHC should i run into perf problems.
Clean is unfortunately windows-focused, as well as web
Idris only has sparse opengl bindings, and recently Edwin even suggested people not even use it because it's more a "learning experience" lang.
Keeping watch on Idris2 though, and even played with it a little bit.
Nim is cool though, and even satisfies my FP preference until idris2 is ready.
>>
>>78817187
>uses OpenGL and is concerned about language performance
>>
>>78817187
did you ever try rust or did you get brainlet filtered?
>>
>>78816844
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>


int main(int argc, char* argv[])
{
int *numArray = malloc(argc * sizeof *numArray);
pid_t p;
int fd[2];
pipe(fd);
p = fork();
//error checks

if(p == 0){//child process
int sum = 0;
int sumBuf = 0;
close(fd[1]);//close write end
for(int i = 0; i < argc-1; ++i){
read(fd[0], &sumBuf, sizeof(int));
sum += sumBuf;
}
close(fd[0]);//close read end
return sum;//return sum from child process
}
else{//parent process
int sum = 0;
close(fd[0]);//close read end
for(int i = 0; i < argc-1; ++i){
numArray[i] = atoi(argv[i+1]);
write(fd[1], &numArray[i], sizeof(int));
}
close(fd[1]);//close write end of pipe
sum = p;
printf("Sum = %d", sum);
return 0;
}
free(numArray);
return 0;
}


tell me why it's sum is wrong then
>>
>>78817170
rust is just *yuck* tbqh
>>
>>78817198
only for one project hopefully, but opengl with C-like performance should never give me problems. But currently working on a "from scratch" vulkan lib in my spare-spare time though. I just want to get more familiar with vulkan and graphics before i move over.
>>78817213
Rust is too C++-ish for me, syntax-wise. My autism just can't handle it.
Nim has really spoiled me with no more ;s, and optional parens for arg passing.
>>
Is the overhead of the abstractions of high level languages like Python due to how the chip architecture is implemented, or is would it be the same for any touring machine?

I guess what I'm asking is if there could be a chip designed for these high level abstractions that make them not have as much overhead.
>>
>>78817256
high level abstractions have nothing to do with python being so shit at performance
>>
pls explain what the fuck is a sparse vector
>>
>>78817281
sparse: look at all those 0s
dense: look at all those ! 0s
>>
>>78817254
>Rust is too C++-ish for me, syntax-wise
it's really not that similar to C++
>My autism just can't handle it.
explains the nim
>>
Gonna fuck with C++ for the first time in my life to do some CompSci learning. Anyone recommend an IDE?
>>
>>78817187
haxe?
Ocaml based language for videogames, looks like nim.
https://haxe.org/
>>
>>78817310
>it's really not that similar to C++
just too many :: and <>s, as well as tedium in general to do the average thing.
I'd rather use Mercury at that point because it's atleast a new paradigm and has interesting things.
>>
Any UIUC grads in here?
>>
>>78816168
float dotp(Vec a, Vec b) {
return a.x * b.x + a.y * b.y;
}
>>
>>78817346
>haxe?
plagued by swift-tier compile times due to its cross-compile nature
And its ecosystem is a bit of a clusterfuck.
I've tried it as well.
>>
What's it like working at faang?
>>
>>78817226
it looks like you're just setting sum to the child pid, then printing it. try waiting for the child.
>>
>>78817434
Yikes
>>
File: 1605957913015.png (60 KB, 595x318)
60 KB
60 KB PNG
>>78816566
>Tnhat's literally not even possible
Cope
>>
>>78816426
Dolled up version:
#include <algorithm>
#include <vector>

#define SparseVector std::vector<Entry>

struct Entry
{
size_t pos;
double data;
};

void SortSparse(SparseVector& u)
{
std::sort(u.begin(), u.end(), [](Entry a, Entry b)
{
return a.pos > b.pos;
}
);
}

double DotProduct(SparseVector& u, SparseVector& v)
{
SortSparse(u);
SortSparse(v);
auto uI = u.begin();
auto vI = v.begin();
double result = 0;
while (uI != u.end() && vI != v.end())
{
if (uI->pos == vI->pos)
{
result += uI->data * vI->data;
uI++;
vI++;
continue;
}
if (uI->pos > vI->pos)
{
vI++;
continue;
}
if (uI->pos < vI->pos)
{
uI++;
continue;
}
}
return result;
}
>>
>>78817497
See >>78817487
>>
>>78817508
Elaborate.
>>
>>78817527
I'll just post how I'd do it, except I'll leave the opening curly braces on separate lines.
>>
>>78817494
Based Rust
>>
>>78817497
>
{
ignored once again
>>
>>78817550
who cares where the braces goes. the code is the same
>>
>>78817357
for more than 2 elements vectors
float dotp(DynArr a, DynArr b, int len) {
int i;
float res = 0;
for (i = 0; i < len; ++i) {
res += a.arr[i] + b.arr[i];
}
return res;
}
>>
>>78817572
I know, but I prefer them on the same line.

It probably would have been easier just to state the changes, as I didn't change much.
#include <algorithm>
#include <vector>

namespace
{
struct Entry
{
size_t pos;
double data;
};
}

using SparseVector = std::vector<Entry>;

void sortSparse(SparseVector& u)
{
std::sort(u.begin(), u.end(), [](Entry a, Entry b)
{
return a.pos > b.pos;
}
);
}

double dotProduct(SparseVector& u, SparseVector& v)
{
sortSparse(u);
sortSparse(v);
auto uI = u.begin();
auto vI = v.begin();
double result = 0;
while (uI != u.end() && vI != v.end())
{
if (uI->pos == vI->pos)
{
result += uI->data * vI->data;
uI++;
vI++;
}
else if (uI->pos > vI->pos)
{
vI++;
}
else
{
uI++;
}
}
return result;
}
>>
>>78817463
so something like
int main(int argc, char* argv[])
{

pid_t p;
int fd[2];
pipe(fd);
p = fork();
//error checks

if(p == 0){//child process
int sum = 0;
int sumBuf = 0;
close(fd[1]);//close write end
for(int i = 0; i < argc-1; ++i){
read(fd[0], &sumBuf, sizeof(int));
sum += sumBuf;
}
close(fd[0]);//close read end
return sum;//return sum from child process
}
else{//parent process
int *numArray = malloc(argc * sizeof *numArray);
// int *numArray = (int*) malloc (argc * sizeof(int));
if (!numArray) {
return EXIT_FAILURE;
}

int sum = 0;
close(fd[0]);//close read end
for(int i = 0; i < argc-1; ++i){
numArray[i] = atoi(argv[i+1]);
write(fd[1], &numArray[i], sizeof(int));
}
close(fd[1]);//close write end of pipe
wait(NULL); // <--- EDITED LINE
sum = p; // problem is here - returning pid, not sum?
printf("Sum = %d", sum);
return 0;
free(numArray);
}
return 0;
}




obviously it's wrong but I'm not sure what's right
>>
>>78817400
There's thousands of videos of "Day in the life of a [insert company here]" on youtube
>>
>>78817592
whoops
res += a.arr[i] * b.arr[i];
>>
>>78817615
You changed barely anything.
Also, the continues are there because they make it easier to tell that the code doesn't segmentation fault. Increment the iterator once, and then check again immediately after that they haven't reached the ending.
>>
>>78816572
Bro, I...
I didn't mean it like that...
>>
>>78817615
how much extra memory does std::sort allocate
>>
>>78817704
it doesnt
>>
>>78817618
the return value from the child does not travel back in time to be returned from fork. read up on what wait does and how you could use it to get the return value. alternatively, you could try using another pipe to send the value back.
>>
>>78817712
depends on the implementation, it can throw bad alloc. you're also adding nlogn comparisons for no reason.
>>
>>78817693
You check in the while loop head if the values have reached the end, and you turned a common check into one that is both less readable and less performant.

The change of placing Entry in to an anonymous namespace is quite important, now that generic name isn't polluting or conflicting with everything that imports this.

You shouldn't write function names in PascalCase, this isn't C#.

Finally, the indentation within sortSparse was terrible originally, and not consistent with indentation elsewhere.
>>
>wake up
>suddenly realiy that std::sort works faster than qsort
>C++ has the potential to generate code much better optimized than C

is this truly the end of an era
>>
>>78817792
It's basically just because it's forced to be in the header because of C++ bloat lmao, otherwise only calling it with the same type of function pointer would achieve the same thing
>>
>>78817792
do you live under a rock
>>
>>78817808
>indirect function call
>no type info
Yeah, sure.
>>
>>78817781
>You check in the while loop head if the values have reached the end
Yes, that's what the continue does, it rechecks the while condition and restarts the loop.
>Finally, the indentation within sortSparse was terrible originally, and not consistent with indentation elsewhere.
Bro it was a single incorrect tab.
>>
>>78817792
>20 years late
Good
>>
>>78817781
>You shouldn't write function names in PascalCase, this isn't C#.
>le epic bikeshedding discussion over style

>>78817808
C++ optimization has nothing to do with "being in a header" and everything to do with being a better language.
>>
>>78817867
you dont know anything
>>78817838
you didnt read the post
>>
>>78817781
The autism code style force strikes again.
>>
>>78817910
anyone who posts { on the next line should be culled desu
>>
Do you expect the average C++ programmer to know about endianness and advanced bitwise operations?
>>
>>78817842
You don't need to use continue in each case if you used if-else, and your explicit check of what would be the else case can't be optimised away, you can check using godbolt.

>>78817867
No reason to go against common conventions, you could see he was also using PascalCase for types as well so you can't tell the difference between a function or constructor call without using an IDE or being familiar with all functions and types.

>>78817842
I forgot to mention your usage of #defineover using.

>>78817910
His code had obvious flaws, why wouldn't I point them out?
>>
>>78817910
rustfmt doesn't have this problem
>>
>>78817923
Don't the only thing C++ programmers do nowadays is seethe on 4chan instead of actually doing anything productive?
>>
>>78817923
no, i expect them to write code that only works on le machines. not sure what you mean by advanced bitwise operations
>>
>>78817948
baste
>>
>>78817923
>advanced bitwise operations
What?
>>
>>78817985
>t. C++ programmer
>>
>>78817718
I have now read the wait manual page for C but don't see how it would help me return the value I seek. Wait will only return PIDs. I tried doing
int childVal = -1;
wait(&childval);

called before I print assign and print sum, but it didn't seem to make a meaningful difference I also tried changing 'return' in the cihld process to 'exit'

i think im too dumb to set up a pipe from child to parent unfortunately
>>
>>78817947
>obvious flaws
>common conventions
>>
>>78817996
there are like 1000 examples online
>>
My code looks like this
pub fn map(&self, matrix: Matrix) -> Self {
let min = matrix
.map_rect(Rect::from_wh(self.width.min, self.height.min))
.0
.size();
let size = matrix
.map_rect(Rect::from_wh(self.width.size, self.height.size))
.0
.size();
let expand_width = self
.width
.expand
.map(|x| matrix.map_vector(Vector::new(x, 0.0)).x);
let expand_height = self
.height
.expand
.map(|y| matrix.map_vector(Vector::new(0.0, y)).y);
// expand?
Self {
width: LayoutDimension {
min: min.width.abs(),
size: size.width.abs(),
expand: expand_width,
},
height: LayoutDimension {
min: min.height.abs(),
size: size.height.abs(),
expand: expand_height,
},
}
}

So her code can look like this
component.size(input_state, time_state).map(matrix)
>>
>>78817993
Seriosly now, what are advanced bitwise and endianness?
>>
>>78817890
>you dont know anything
Nice argument. Prove me wrong. Surely if C is such a good language, the standard library implementers would make the function just as fast, since the only optimization (bloat) C++ made is "being in a header", right?
>>
>>78818018
Read the whole post, then formulate an argument.
>>
>>78818051
Is there a better name for map? I'd be confused by it because map usually takes some type of closure or function as an argument and not an object.
>>
>>78818073
no need, there's literally no such thing as "common convetion" or "obvious flaws"
>>
>>78818038
I actually got it, I didn't realize I had to divide the value by 255.
/* sum input from command line arguements using pipe and fork */
/* currently retruns the wrong value */

#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>


int main(int argc, char* argv[])
{

pid_t p;
int fd[2];
pipe(fd);
p = fork();
//error checks

if(p == 0){//child process
int sum = 0;
int sumBuf = 0;
close(fd[1]);//close write end
for(int i = 0; i < argc-1; ++i){
read(fd[0], &sumBuf, sizeof(int));
sum += sumBuf;
}
close(fd[0]);//close read end
// exit(sum);
return sum;//return sum from child process
}
else{//parent process
int childval = -1;
int *numArray = malloc(argc * sizeof *numArray);
// int *numArray = (int*) malloc (argc * sizeof(int));
if (!numArray) {
return EXIT_FAILURE;
}
int sum = 0;
close(fd[0]);//close read end
for(int i = 0; i < argc-1; ++i){
numArray[i] = atoi(argv[i+1]);
write(fd[1], &numArray[i], sizeof(int));
}
close(fd[1]);//close write end of pipe
wait(&childval);
// wait(&sum);
// wait(&p);
sum = p; // problem is here - setting sum to child pid, not sum?
// printf("Sum = %d \n", sum);
printf("Sum = %d \n", childval / 255);
return 0;
free(numArray);
}
return 0;
}



I would like to learn how to do it with pipes as well though
>>
>>78817963
>>78817973
>>78817985
Ya'll know what I mean. I'm surrounded by geniuses at work and I've started to second guess myself.
>>
>>78818060
I don't know what he means by "advanced" bitwise operators, but endianness is whether the numbers are starting with the least digit, or starting with the highest digit. It's a bit of a hassle to convert between them, so it's good that the industry has pretty much settled on one of the two.
>>
>>78818099
`map` as in mapping a point on a plot using geometric transformation. That's game engine code right there, and that's the code to deal with your shitty UI layout rules that no one actually uses irl
>>
>>78818113
the right way would be to call WEXITSTATUS on childVal I believe, dividing by 255 is just an implementation detail and might not always work.
Setting up a pipe shouldn't be too hard, you already got one going in one direction, so it can't be that different to set one up in the opposite direction.
>>
>>78818099
map is the most overloaded word in programming, not much you can do about it
>>
>>78818128
i'm writing a little bcd library in c which stores the digits. currently only integers but i'm slow so ¯\_(ツ)_/¯
so, if i can easily test whether the first digit is 1 or 9 with it means i know endianness?
>>
>>78817236
hiroshimoot needs to upgrade whatever the highlighter is so it supports rust and single ticks don't fuck everything up.
>>
>>78818289
and lisp
why can't it be like [code lang=rust]?
>>
>>78818289
Just use a real language, like Javascript.
>>
>>78818289
>>78818301
he only cares about languages that are actually used in the real world
>>
>>78818324
i only use languages that are used in the imaginary world
>>
>>78817494
>the i9 in the 2016 macbook pro was bad because of thermal throttling
>>
>>78818324
programming != java corporate code monkeing
>>
>>78818306
>Javascript
>real language
Choose one
>>
>>78818346
Yes.
>>
Why is Haskell so shit on ARM?
>>
>>78818356
so second one. nice choice
>>
Can someone please help me with this SQL?

SELECT class.cname FROM enroll RIGHT JOIN class ON enroll.cname=class.cname WHERE room='R128' GROUP BY enroll.cname HAVING COUNT(enroll.cname)>4;

I want get all the classes in room R128 and also all classes that have 5 or more students enrolled. I can get the two results separately but I don't understand how I can combine them into one query
>>
>>78818357
Is it?
>>
>>78818357
what compiler?
>>
>>78818366
Javascript is the most popular programming language. That's how you know it's good.
>>
>>78818397
6lynbXDyJFmWirDo2ICD
NKZzklBCaAYHYLSAEdt6
VyL96zlklOhdohM8C8fa
EKphaldgfb7hZwMHkYAw
O1iK0K9D8tgE5HoQiisp
r3gF9hqlKiqsb2JJgzgL
0DAI9l9pVvHYfI6hUmbW
BmbyGzrnUfnMN0ekphZe
1I6IMIOy0POKBMagXUlS
pWE4QtpG2409oEeWzOJQ
>>
>>78818387
Let's not pretend like there are multiple ones.
>>
why use (quote (my list)) and not '(my list)?
also, what is really the difference between symbols and strings? like wtf? what are symbols even useful at?
>>
>>78818486
You would typically use the shorthand '.
CL-USER> (eq "foo" "foo") 
NIL
CL-USER> (eq :foo :foo)
T
>>
>>78818614
i mean i understand they are different language constructs and shite but what are symbols actually used at? also, is : a reader macro that i've heard about? what does it expand to?
>>
> Docker question:

So I just recently joined a software company and I have noticed that we're having trouble configuring everything in each machine so one person can work on a project locally, I helped a new guy and we had a lot of problems configuring java, maven and STS4 in his system.

So that's where Docker comes in, right? Or at least part of it

I create a Docker image configuring everything and then anyone can get that image and install it and it should work.

But, how do I interact with the system, like if I want to run certain programs do I do it via terminal?

Also, some of the projects use Docker, so I guess this would be something like Docker in Docker, where I create an image for a project that utilizes Docker as well.

Do I get it right or am I lost here?
>>
So are apps best developed completely in React Native?
>>
>>78818720
is that a game engine?
goto /vg/agdg/
>>
>>78818732
what are you talking about? I'm asking about android/ios app development, not games
>>
>>78818720
No, use Flutter or go native native.
>>
File: SICP.png (76 KB, 1208x357)
76 KB
76 KB PNG
>SICP isn't heavy on math
>>
>>78818486
>why use (quote (my list)) and not '(my list)?
no one uses quote explicitly. it is a lisp form like any other, but the shorthand syntax is always the way you want to use it
>also, what is really the difference between symbols and strings?
a symbol is an interned string, with some extra features. imagine you're writing C and you malloc two sets of 9 bytes and set them both to the ascii value "fizzbuzz" (+ the null terminator). are they equal? they are equal in the sense that they have the same value, but to make sure of that you'd need to compare all the 9 bytes. when you have two equal symbols in lisp, they are literally the same object in memory, so only a pointer comparison needs to be done. if they point to the same place, they are equal

symbols can also be used semantically, like this:
> (define foo 'length)
> ((eval foo) '(1 2 3 4 5))
5
>>
>>78818785
>he thinks that is heavy math
>>
>>78818786
oh, so symbols are like a global hashmap or something? because how else does the implementation search for an existing symbol already right?
>>
>>78818775
why? are you just being hipster? I know some React from webdev (non-professional) so was hoping to leverage that
>>
>>78818830
are stored in*
sorry i'm sleepy and i don't understand why but i have trouble forming sentences and words into coherent thoughts
>>
>>78818785
they could easily teach that in middle school
>>
>>78818785
ngmi
>>
>>78818846
Your hopes are irrelevant.
>>
>>78818848
Sleep is important anon, especially for programming. Fatigue makes you dumb.
>>
Holy fuck why are you Redditors so triggered by Python? The language is not your uncle who raped you. Calm down.
>>
>>78818785
>SICP isn't heavy on math
Who told you this.
>>
>>78818886
you're right you know
good night then anon
>>
>>78818826
>>78818854
>>78818866
Find me someone who knows what a continuous function is and isn't at least a college student. Heck, some countries don't even do logarithms until college. Plenty of people can't even read "f(a)<0<f(b)" or know what "a zero" means.
>>
>>78818892
what is this reddit post you're making? nobody's trigger here but you
>>
>>78818904
>Americans
>>
new thread
>>78818922
>>78818922
>>78818922
>>
>>78818906
I'm only triggered by your shitty grammar.
>>
>>78818830
>>78818848
it is interned when it's used for the first time, so... yes, it's like a global hashmap. other languages also do this for literal strings
>>
>>78818897
/dpt/ has this conversation every few threads. Plenty of examples here https://archive.rebeccablacktech.com/g/search/text/%22SICP%22%20%22Math%22/

>>78818920
English as well. I didn't know what a logarithm was until I was 17.
>>
>>78818658
What I showed was the difference between strings and keywords (a type of symbol that I assume is what you meant). For clarity, a symbol is just an object that represents a thing in Lisp, whether that is a function or a variable, or some other entity.
You'll typically see these in functions with keyword arguments. : is used to reference a symbol from a package. mypackage:foo will get you the symbol from mypackage. If you omit :foo, you will get the symbol from the KEYWORD package by default. In other words, it is equivalent to keyword:foo. These symbols always evaluate to themselves, and are constants. In my opinion they are cleaner and slightly more efficient than using strings because of this.
>>
>>78818963
>If you omit :foo,
Should be "If you omit mypackage so it reads as :foo,"
>>
>>78817923
yes, it is to be expected



Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.