From 23ae2a7190fcaa49cc4fcadc9e6123b210d489cf Mon Sep 17 00:00:00 2001 From: Jon Ross-Perkins Date: Tue, 18 Jun 2024 12:01:33 -0700 Subject: [PATCH] Update images from snippet changes. (#4061) Note, to see the results, here's a [README link](https://github.com/carbon-language/carbon-lang/blob/654a06e0af7886dc43f52d35f4d11f32c5e8da9d/README.md) (note this is for the 654a06e commit) Enumerating changes: - Finish the work started in #3735 by updating the images. - Reverts changes to vector initialization style made in #3735, instead preferring https://abseil.io/tips/88 style - Switch array syntax to match [#syntax discussion](https://discord.com/channels/655572317891461132/709488742942900284/1219410082719207444) - Some nuanced highlighting changes to try matching what I'm seeing in GitHub. - The original intent was to match GitHub's highlighting, at least for C++; Carbon highlighting is expected to be poor because it's not a supported language. --- docs/images/carbon_snippet.svg | 2 +- docs/images/cpp_snippet.svg | 2 +- docs/images/mixed_snippet.svg | 2 +- docs/images/snippets.md | 15 ++++++++------- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/images/carbon_snippet.svg b/docs/images/carbon_snippet.svg index 187183915c7b..4d2e3f84982e 100644 --- a/docs/images/carbon_snippet.svg +++ b/docs/images/carbon_snippet.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/docs/images/cpp_snippet.svg b/docs/images/cpp_snippet.svg index 00ff2817e63e..6216934bfa3c 100644 --- a/docs/images/cpp_snippet.svg +++ b/docs/images/cpp_snippet.svg @@ -1 +1 @@ - + \ No newline at end of file diff --git a/docs/images/mixed_snippet.svg b/docs/images/mixed_snippet.svg index d4ec957bcc87..8ec28403f295 100644 --- a/docs/images/mixed_snippet.svg +++ b/docs/images/mixed_snippet.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/docs/images/snippets.md b/docs/images/snippets.md index d0d542d2a94e..2bfffeb00af2 100644 --- a/docs/images/snippets.md +++ b/docs/images/snippets.md @@ -67,7 +67,7 @@ void PrintTotalArea(std::span circles) { } auto main() -> int { - std::vector circles{{.r = 1.0}, {.r = 2.0}}; + std::vector circles = {{.r = 1.0}, {.r = 2.0}}; // Implicitly converts `vector` to `span`. PrintTotalArea(circles); return 0; @@ -85,7 +85,7 @@ class Circle { var r: f32; } -fn PrintTotalArea(circles: Slice(Circle)) { +fn PrintTotalArea(circles: [Circle]) { var area: f32 = 0; for (c: Circle in circles) { area += Math.Pi * c.r * c.r; @@ -95,8 +95,8 @@ fn PrintTotalArea(circles: Slice(Circle)) { fn Main() -> i32 { // A dynamically sized array, like `std::vector`. - var circles: Array(Circle) = ({.r = 1.0}, {.r = 2.0}); - // Implicitly constructs `Slice` from `Array`. + var circles: array [Circle] = ({.r = 1.0}, {.r = 2.0}); + // Implicitly constructs a slice from the array. PrintTotalArea(circles); return 0; } @@ -107,6 +107,7 @@ fn Main() -> i32 { ```cpp // C++ code used in both Carbon and C++: #include + struct Circle { std::float32_t r; }; @@ -116,7 +117,7 @@ package Geometry; import Cpp library "circle.h"; import Math; -fn PrintTotalArea(circles: Slice(Cpp.Circle)) { +fn PrintTotalArea(circles: [Cpp.Circle]) { var area: f32 = 0; for (c: Cpp.Circle in circles) { area += Math.Pi * c.r * c.r; @@ -131,8 +132,8 @@ fn PrintTotalArea(circles: Slice(Cpp.Circle)) { auto main() -> int { std::vector circles = {{1.0}, {2.0}}; - // Carbon's `Slice` supports implicit construction from `std::vector`, - // similar to `std::span`. + // A Carbon slice supports implicit construction + // from `std::vector`, similar to `std::span`. Geometry::PrintTotalArea(circles); return 0; }